'random.shuffle' method is used to shuffle a list, sequence.
Signature
random.shuffle(x[, random])
Example
random.shuffle(my_list)
shuffle_list.py
import random
primes = [2, 3, 5, 7, 11, 13]
print('Before shuffling, primes -> ', primes)
random.shuffle(primes)
print('After shuffling, primes -> ', primes)
Output
Before shuffling, primes -> [2, 3, 5, 7, 11, 13] After shuffling, primes -> [11, 5, 13, 7, 2, 3]
No comments:
Post a Comment