Shuffle a list
This snippet can be used to randomize the order of the elements in a list. Note that shuffle works in place, and returns None.
Python: 3.0    Fatos Morina    03 Jul 2021   0
Login to upvote
1
2
3
4
5
from random import shuffle

foo = [1, 2, 3, 4]
shuffle(foo) 
print(foo) # [1, 4, 3, 2] , foo = [1, 2, 3, 4]
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com