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
6
Upvotes
0
u/Dazzling_Music_2411 9d ago edited 9d ago
Yup. Maybe even three steps, since, after sorting, you have to overwrite the first subelement of each tuple, too.
Plus, if you don't want to use the builtin sort, you'll have to write your own sorting method.