To shuffle an array (or list) in Python, you can use the random.shuffle()
function from the built-in random
module. Here's an example:
main.py80 chars6 lines
Output:
main.py16 chars2 lines
The random.shuffle()
function shuffles the elements of the list in place, meaning it modifies the original list. If you don't want to modify the original list, you can make a copy of it first and shuffle the copy instead:
main.py123 chars7 lines
Output:
main.py16 chars2 lines
gistlibby LogSnag