I have a list of tuples
student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
I've been trying different ways to sort this, using itemgetter and lambda functions. Sorting by two indices of the tuples can be done with itemgetting and the lambda function, but it must return a tuple. I can't seem to find that anywhere in the documentation that the key function works on tuples.
Anyway, I wanted to know what itemgetter() actually returns, so this works (copied from the itemgetter documentation):
f = itemgetter(1)
print f(student_tuples[0])
----->A
Is there any way to do this WITHOUT having to reassign itemgetter to a variable? It looks like two arguments are being passed, but something like
print itemgetter(1, student_tuples[0])
-----><operator.itemgetter object at 0xf7309c8c>
doesn't give me anything useful.
I'm just fiddling around trying to learn Python and this is confusing me. I don't know where in itemgetter student_tuples[0] is being added as an argument.