Below is my code and i am trying to sort the tuple with respect to 2nd element.
list = ["abc14_90","abc44_88","abc14_89"]
listLength = len(list)
for i in range(0,listLength):
tempList = list[i].split('_')
tempList1 = tempList[0].split('c')
if(i==0):
tupleNumber = [(list[i], int(tempList1[1]),int(tempList[1]))]
else:
tupleNumber = tupleNumber + [(list[i], int(tempList1[1]),int(tempList[1]))]
print (tupleNumber)
sorted(tupleNumber, key=lambda x: x[2])
print (tupleNumber)
Expected Output:
[ ('abc44_88', 44, 88), ('abc14_89', 14, 89),('abc14_90', 14, 90),]
Output Observed:
[('abc14_90', 14, 90), ('abc44_88', 44, 88), ('abc14_89', 14, 89)]
Basically the sort seems to have no effect.