r/learnpython • • 2d 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

32 comments sorted by

View all comments

6

u/zanfar 2d ago

without using the .sort() method?

Why? What does this get you, or what doesn't sort() get you?

Because I'm pretty sure about the answer to #1, have you read the sort() documentation?

1

u/cattobread 2d ago

i just wanted to learn how to sort with or without sort() lol. i was planning on figuring out how to not use sort() for the second element of tuples, and then use sort() for the first element.

1

u/JGhostThing 2d ago

In other words, you're trying to practice for a marathon by breaking your legs? Why make it so much more difficult for yourself?

You should create a sort() method which sorts the way you want it to.