[Tutor] Kent's top poster script operator.itemgetter()

Sander Sweers sander.sweers at gmail.com
Sat Jan 3 00:12:41 CET 2009

Hello All,

While trying to inderstand Kent's script [1] I struggle on the use of
operator.itemgetter(1) from the following piece of code. I understand
it makes it sort on the second value of the counts.iteritems but I do
not understand how  operator.itemgetter(1) works.

for name, count in
sorted(counts.iteritems(),key=operator.itemgetter(1), reverse=True):

Could someone help me understand this?


[1] http://mail.python.org/pipermail/tutor/2009-January/065986.html

More information about the Tutor mailing list