For example:
I have a list of tuples like:
data = [(1,2,3), (4,3,6), (7,0,9)]
I want the output as:
[(7, 0, 9), (1, 2, 3), (4, 3, 6)]
In the output you can the tuples are sorted in ascending order based on index[1]
data = [(1,2,3), (4,3,6), (7,0,9)]
sorted_by_second = sorted(data, key=lambda tup: tup[1])
print(sorted_by_second)
index={}
data = [(1,2,3), (4,3,6), (7,0,9)]
for i in range(0,len(data)):
index[data[i][1]]=i
for i in sorted(index):
print(data[index[i]])