I’m trying to sort a list of tuples based on the second item in the tuple. When
I run this in IDLE I get the correct output; however, when running inside of a
program, and calling the counter() function, sorted does not seem to work? Any
ideas on why this works in IDLE and not in program would be appreciated. Thank
You.
def getKey(item):
return item[1]
def counter():
L = [("baby", 9999), ("aeuron", 100), ("pablo", 1234)]
sorted(L, key=getKey)
print ("L = ", L)
OUTPUTS THIS (when calling counter inside of program):
L = [('baby', 9999), ('aeuron', 100), ('pablo', 1234)]
OUTPUTS THIS (when running with IDLE – desired output):
[('aeuron', 100), ('pablo', 1234), ('baby', 9999)]
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor