shuffle list python random code example
Example 1: python shuffle list
import random
number_list = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
print ("Original list : ", number_list)
random.shuffle(number_list)
print ("List after shuffle : ", number_list)
Example 2: randomly shuffle array python
import random
l = list(range(5))
print(l)
lr = random.sample(l, len(l))
print(lr)
print(l)
Example 3: random.shuffle
import random
list = [20, 16, 10, 5]
random.shuffle(list)
print("Reshuffled list : ",list)
OUTPUT:
Reshuffled list : [16, 5, 10, 20]