A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-November/040529.html below:

[Python-Dev] "groupby" iterator

[Python-Dev] "groupby" iterator [Python-Dev] "groupby" iteratorOren Tirosh oren-py-d at hishome.net
Sun Nov 30 02:31:09 EST 2003
On Fri, Nov 28, 2003 at 06:24:30PM -0500, Raymond Hettinger wrote:
...
> students.sort(key=extract('grade'))  # key=lambda r:r.grade
> students.sort(key=extract(2))        # key=lambda r:[2]

Why should the extract function interpret a string argument as getattr
and an int argument as getitem? 

I find the explicit version more readable:

students.sort(key=attrgetter('grade'))  # key=lambda r:r.grade
students.sort(key=itemgetter(2))        # key=lambda r:[2]
students.sort(key=itemgetter('grade'))  # key=lambda r:r['grade']

    Oren

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4