How do I sort a zipped list in Python?

How do I sort a zipped list in Python?

Quite simple:

sorted(zipped, key=lambda x: x[1])
sorted(zipped, key = lambda t: t[1])

How do I sort a zipped list in Python?

import operator
sorted(zipped, key=operator.itemgetter(1))

If you want it a little bit more faster, do ig = operator.itemgetter(1) and use ig as key function.

Leave a Reply

Your email address will not be published. Required fields are marked *