Sometimes, while working with Python list, we can have a problem in which we need to perform shuffle operation in list. This task is easy and there are straightforward functionalities available in Python to perform this. But sometimes, we need to shuffle two lists so that their shuffle orders are consistent. Let’s discuss a way in which this task can be performed.
Method : Using
zip() + shuffle() +
In this method, this task is performed in three steps. Firstly, the lists are zipped together using
zip(). Next step is to perform shuffle using inbuilt
shuffle() and last step is to unzip the lists to separate lists using * operator.
The original list 1 : [6, 4, 8, 9, 10] The original list 2 : [1, 2, 3, 4, 5] List 1 after shuffle : [6, 10, 4, 8, 9] List 2 after shuffle : [1, 5, 2, 3, 4]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Zipping two lists of lists
- Python | Check whether two lists follow same pattern or not
- Python - Filter unequal elements of two lists corresponding same index
- Python | Ways to shuffle a list
- random.shuffle() function in Python
- numpy.random.shuffle() in python
- Ways to shuffle a Tuple in Python
- Shuffle a deck of card with OOPS in Python
- Shuffle an array in Python
- Python | Program to count number of lists in a list of lists
- Python - Convert Lists into Similar key value lists
- Pandas - How to shuffle a DataFrame rows
- Shuffle a given Pandas DataFrame rows
- Python | Remove duplicate lists in tuples (Preserving Order)
- Python | Interleave multiple lists of same length
- Python program to check whether the values of a dictionary are in same order as in a list
- Creating a sorted merged list of two unsorted lists in Python
- Python | Intersection of two lists
- Python | Union of two or more Lists
- Python | Check if two lists have at-least one element common
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.