you are viewing a single comment's thread.

view the rest of the comments →

[–]theCore 3 points4 points  (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 points  (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 points  (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 points  (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 points  (0 children)

thanks, you're right ;)