I've a zip
object and I want to sort it(based on a specific key).
I've already seen How do I sort a zipped list in Python? but the accepted answer does not work in python 3.6 anymore.
For example
In [6]: a = [3,9,2,24,1,6]
In [7]: b = ['a','b','c','d','e']
In [8]: c = zip(a,b)
In [9]: c
Out[9]: <zip at 0x108f59ac8>
In [11]: type(c)
Out[11]: zip
In [12]: c.sort()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-a21727fa8976> in <module>()
----> 1 c.sort()
AttributeError: 'zip' object has no attribute 'sort'
# Wanted this to be sorted by the first element
In [13]: for l,r in c: print(l,r)
3 a
9 b
2 c
24 d
1 e
In other words how do I make the zip iteration order conform to the sorting order. I'm aware that converting a zip to a list of tuples will allow me to fix this, but I want to retain the zipped object (as it used to be in the good old days of python2.7)