Shuffle/Randomize A List In Python
December 2021
# Shuffle A List In Place
The basic way to shuffle a list is:
#!/usr/bin/env python3
=
The list is shuffled in place and the output of the above script will be something like:
['c', 'e', 'a', 'b', 'd']# Shuffle Items Into A New List
If you want to keep the original list in place, you can use random.sample to make a new list with the shuffled contents like this:
#!/usr/bin/env python3
=
=
end of line