i want to ask if i got a array of list in python like this:
a = [[1, 2, 3, 4, 5, 6],
[1, 2, 3, 4, 5, 6],
[1, 2, 3, 4, 5, 6]]
How do i shuffle within range a[1][1] to a[1][4]?
I only know the normal shuffle
random.shuffle(a)
Take a sample from the sublist, with the sample size set to the same length, then assign that sample back to the slice:
a[1][1:4] = random.sample(a[1][1:4], 3)
This takes a sample of the 3 elements from the source list (producing those same 3 elements in random order), and assigns these right back to the same indices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With