I have never had this problem before but when i try and shuffle a list i get a return of 'None'
import random
c=[1,4,67,3]
c=random.shuffle(c)
print c
The print statement returns 'None' and i dont know why, I have looked around for an answer to this problem but there doesent seem to be anything. I hope i am not making an obvious mistake.
The random.shuffle
function sorts the list in-place, and to avoid causing confusion on that point, it doesn't return the shuffled list. Try just:
random.shuffle(c)
print(c)
This is a nice bit of API design, I think - it means that if you misunderstand what random.shuffle
is doing, then you'll get a obvious problem immediately, rather than a more subtle bug that's difficult to track down later on...
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