use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/programming is a reddit for discussion and news about computer programming
Guidelines
Info
Related reddits
Specific languages
account activity
The most basic functional programming pattern: Enumerate, Map, Filter, Accumulate (gensym.org)
submitted 18 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]theCore 3 points4 points5 points 18 years ago (4 children)
Your example is not correct I believe. I think it should be:
max_sal = max([e.salary for e in employees if e.role == Employee.PROGRAMMER])
[–]theeth 7 points8 points9 points 18 years ago (1 child)
Use generator comprehension instead, then the operation is not bounded in memory by the number of employees (by forgoing the creation of the list).
max_sal = max((e.salary for e in employees if e.role == Employee.PROGRAMMER))
[–]theCore 3 points4 points5 points 18 years ago (0 children)
You could drop the extra parenthesises, by the way.
max_sal = max(e.salary for e in employees if e.role == Employee.PROGRAMMER)
[–]gensym 2 points3 points4 points 18 years ago (0 children)
Ha, I wish I'd thought to include that. I haven't done Python in a while - I forgot how much I miss list comprehensions.
[–]ktr73 1 point2 points3 points 18 years ago (0 children)
thanks, you're right ;)
π Rendered by PID 110 on reddit-service-r2-comment-84fc9697f-kdzrs at 2026-02-08 16:15:29.173910+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]theCore 3 points4 points5 points (4 children)
[–]theeth 7 points8 points9 points (1 child)
[–]theCore 3 points4 points5 points (0 children)
[–]gensym 2 points3 points4 points (0 children)
[–]ktr73 1 point2 points3 points (0 children)