wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

How to shuffle a list in python?

Open in App
Solution

The easiest way to shuffle a list is using the shuffle() in-built function of the random library. If we pass a list through the shuffle() in-built function then it will return the shuffled list.

Example:

import random #importing the random library
myList = [1, 2,3, 4]
random.shuffle(myList) # shuffling the list
print(myList)

Output:
[3, 2, 1, 4]

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Frequency Distribution Table
STATISTICS
Watch in App
Join BYJU'S Learning Program
CrossIcon