How to randomize a sorted list of strings in Python

2 Answers

0 votes
import random

sorted_list = ['all', 'any', 'chunk', 'column', 'combine', 'intersect']

# Randomize the list
randomized_list = random.sample(sorted_list, len(sorted_list))

print(randomized_list)


'''
run:

['intersect', 'combine', 'all', 'chunk', 'column', 'any']
   
'''

 



answered Apr 18 by avibootz
0 votes
import random

lst = ['all', 'any', 'chunk', 'column', 'combine', 'intersect']

# Randomize the list
random.shuffle(lst)

print(lst)


'''
run:

['intersect', 'all', 'combine', 'chunk', 'any', 'column']
   
'''

 



answered Apr 18 by avibootz
...