list1 = [3,2,4,1,1] list2 = ['three', 'two', 'four', 'one', 'one2'] list1, list2 = zip(*sorted(zip(list1, list2)))
Here is what the above code is Doing:
1. zip(*sorted(zip(list1, list2)))
2. sorted(zip(list1, list2))
3. zip(list1, list2)
4. zip(*zip(list1, list2))
1. zip(*sorted(zip(list1, list2)))
This is the same as:
zip(*sorted(zip(list1, list2)))
Which is the same as:
zip(*sorted([(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)]))
Which is the same as:
zip([3, 2, 4, 1, 1], [‘three’, ‘two’, ‘four’, ‘one’, ‘one2’])
Which is the same as:
[(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)]
2. sorted(zip(list1, list2))
This is the same as:
sorted([(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)])
Which is the same as:
[(1, ‘one’), (1, ‘one2’), (2, ‘two’), (3, ‘three’), (4, ‘four’)]
3. zip(list1, list2)
This is the same as:
zip([3, 2, 4, 1, 1], [‘three’, ‘two’, ‘four’, ‘one’, ‘one2’])
Which is the same as:
[(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)]
4. zip(*zip(list1, list2))
This is the same as:
zip(*[(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)])
Which is the same as:
zip([3, 2, 4, 1, 1], [‘three’, ‘two’, ‘four’, ‘one’, ‘one2’])
Which is the same as:
[(3, ‘three’), (2, ‘two’), (4, ‘four’), (1, ‘one’), (1, ‘one2’)]