Say I have:
list=[('mike', 22.0), ('john', 33.0)]
I want to print a list of just the numbers, smallest to largest. I tried doing this:
for s in list:
print(sorted(s[1]))
But it said 'int object is not iterable'?
If i do this, it works ( output is: [22,33])
print (sorted(s[1] for s in list))
How does the 2nd one work and what's the difference between the 1st and 2nd attempt? Hard time understanding the list comprehension technique.
BTW, the final goal is to print the NAME of the person will the lowest mark. But I'm trying to understand this part first before I associate the name with the mark. Dict would make it so much easier to assign key-values though
s[1]and see what you get. Then type in[s[1] for s in list]and see what you get. Then see if it makes more sense.dicthere?