python shuffle two lists together

Solutions on MaxInterview for python shuffle two lists together by the best coders in the world

showing results for - "python shuffle two lists together"
Jona
27 Mar 2017
1# Example usage using random:
2import random
3# Say you want to shuffle (randomly reorder) the following lists in the
4# same way (e.g. because there's an association between the elements that
5# you want to maintain):
6your_list_1 = ['the', 'original', 'order']
7your_list_2 = [1, 2, 3]
8
9# Steps to shuffle:
10joined_lists = list(zip(your_list_1, your_list_2))
11random.shuffle(joined_lists) # Shuffle "joined_lists" in place
12your_list_1, your_list_2 = zip(*joined_lists) # Undo joining
13print(your_list_1)
14print(your_list_2)
15--> ('the', 'order', 'original') # Both lists shuffled in the same way
16--> (1, 3, 2) # Use list(your_list_2) to convert to list
Simón
11 Apr 2017
1from sklearn.utils import shuffle
2a_shuffled, b_shuffled = shuffle(np.array(a), np.array(b))
queries leading to this page
python random shuffle two listspython shuffle 2 lists python3 shuffle to lists the samerandomly merge three lists pythonshuffle 2 lists the samepython shuffle multiple listsshuffle two lists in the same orderhow to shuffle two lists together in javashuffle 2 dataset at the same timepython shuffle 2 lists togethermerge two list with random orderpython shuffle two lists togethercombine and shuffle two lists in pythonpython randomize 2 lists equallyhow to make two different lists randomly shuffle in python and the output of both list is in the same indexshuffle 2 listsshuffle python avec 2 lists the same wayshuffle 2 list pythonshuffle two lists together to oneshuffle two list in the same way pythonshuffle 2 lists pythonhow to shuffle two lists in c 23shuffle two lists the same pythonpython shuffle two list the same wayshuffle two lists togethershuffle two lists in the same order pythonshuffle two lists at the same time python 3how to shuffle two lists having same orderpython randomize 2 lists equally one lineshuffle two lists together pythonshuffle two lists the same way pythonpython shuffle two lists the same waypython same random permutation of 2 listhow to shuffle two lists in pythonpython shuffle two lists in the same wayshuffle two lists together python numpyhow to shuffle two lists in csharpshuffle two arrays the same way pythonpython shuffle two lists at once with same orderrandomly shuffle 2 lists the same wayrandom shuffle two listsshuffle multiple lists pythonadd two list and then shuffle pythonhow to shuffle two lists the same way pythonshuffle 2 lists python in the same waypython shuffle two lists together