[Python] How do you sort a list of tuples without using sort() or lambda() function?

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have to sort a list of tuples without using any built-in function (like sort() or lambda()).

    I know how to sort a normal list like so:

    a=[2,1,3]
    for i in range(0, len(a)):
    for j in range(i+1,len(a)):
    if (a>a[j]):
    a,a[j]=a[j],a
    return a


    My output is: [1,2,3]

    However, when it comes to sorting a list of tuples like (("b", 32), ("c", 1), ("a", 23)) and that I have to reorder it in order of the second element without using sort() or lambda() or any in-built function, I don't know how to do it. Can someone help me please?

    Continue reading...

Compartilhe esta Página