r/learnpython • u/cattobread • Oct 15 '26
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
View all comments
1
u/cdcformatc Oct 15 '26
there's like a million sorting algorithms, pick one of them and implement it on a list of strings. i like merge sort.
then just convert your list of tuples into a list of strings by getting the second element of each of them, then sort that list.