"Sorting Lists", What does item[1] stand for here?

Hi,

What does the [1] stand for in this code:

items = [
    ("Product1", 10),
    ("Product2", 9),
    ("Product3", 12)
]


def sort_item(item):
    return item[1] 


items.sort(key=sort_item)
print(items)

Or in this one:

items = [
    ("Product1", 10),
    ("Product2", 9),
    ("Product3", 12)
]


items.sort(key=lambda item:item[1])
print(items)

Mosh says it will “return item of 1,” still don’t know what 1 is, as 2 doesn’t work and 0 returns the original list order. I thought maybe it was a boolean, like True or False situation, but it says it’s an integer.

Note: The code works, I just want to understand HOW it works.

Thanks!

I rewatched the video about 3 times, and now I’m thinking it must be the position inside each tuple, which has 0 and 1 only. Rookie mistake.

yes, you are correct

1 Like