How to shuffle a list of objects in Python?

PythonServer Side ProgrammingProgramming

Python has a random module which provides randomization related functions. The shuffle() function randomizes the sequence of items in a list.

>>> import random
>>> l1=['aa',22,'ff',15,90,5.55]
>>> random.shuffle(l1)
>>> l1
[22, 15, 90, 5.55, 'ff', 'aa']
>>> random.shuffle(l1)
>>> l1
['aa', 'ff', 90, 22, 5.55, 15]
raja
Published on 05-Mar-2018 09:49:58
Advertisements