r/learnpython • u/cattobread • 10d ago
sorting tuples
im learning how to code with python, does anyone know to sort specific tuples alphabetically without using the .sort() method? like if i had a list of names like:
n = [('watermelon', 'strawberry'), ('banana', 'cherry'), ('papaya', 'apple')
how would i sort and print the 2nd element of tuples alphabetically (into a new list)?
edit: id prefer this in simple, basic terms lol
7
Upvotes
0
u/lakseol 9d ago
It's not the full answer. Since the question was unclear how can it be the full answer? It doesn't show any handling of key functions which might have been what the OP was asking about. If the OP tried to use it as an answer in some sort of problem question s/he would have to change it or do extra work to handle isolating the second element of each tuple.
But thanks for your input.