Shuffle List in Python
List is an ordered sequence of items. You can shuffle these items using shuffle() function of random module.
shuffle() function takes a sequence and shuffles the order of elements.
Following is the quick code snippet to shuffle a list.
random.shuffle(listA)
Run Example 1: Shuffle a List
In this example, we shall shuffle a list in Python using random package.
Python Program
import random
#initialize a list
listA = [2, 8, 4, 3, 1, 5]
#shuffle list
random.shuffle(listA)
print(listA)
Run Output
When the above program is run, it prints a shuffled list. We have run it many times, to see the order of elements change.

Example 2: Shuffle a List of Strings
In this program, we shall take a list of string and shuffle them.
Python Program
import random
#initialize a list
listA = ['a', 'b', 'c', 'd', 'e']
#shuffle list
random.shuffle(listA)
print(listA)
Run Output

During each run, the list of strings is shuffled.
Summary
In this tutorial of Python Examples, we learned how to shuffle a list, with the help of well detailed examples.
Related Tutorials
- Python Program to Find Largest Number in a List
- Python List without Last Element
- How to Sort Python List?
- Python – Convert List to Dictionary
- Python List of Dictionaries
- Python – Check if Element is in List
- Python Program to Find Unique Items of a List
- How to Reverse Python List?
- Python – Check if List Contains all Elements of Another List
- How to Insert Item at Specific Index in Python List?