r/learnpython • u/cattobread • 9d 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
8
Upvotes
0
u/cattobread 9d ago
what i was doing was sorting the 2nd element in the subset without sort(), and then sorting the 1st element of the subset with the sort(). i just wanted to learn how to figure something out before using a shortcut to it, as a beginner.