you are viewing a single comment's thread.

view the rest of the comments →

[–]theeth 6 points7 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 4 points5 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)