Write a Python Program to Sort the List According to the Second Element in Sublist


Topic: Write a Python Program to Sort the List According to the Second Element in Sublist

Solution

a=[['A',34],['B',21],['C',26]]
for i in range(0,len(a)):
    for j in range(0,len(a)-i-1):
        if(a[j][1]>a[j+1][1]):
            temp=a[j]
            a[j]=a[j+1]
            a[j+1]=temp



List all Python Programs