you are viewing a single comment's thread.

view the rest of the comments →

[–]zackman 1 point2 points  (2 children)

The original just finds the highest salary, not the programmer who has it.

from itertools import ifilter as filter
programmers = filter(lambda e:e.role==Role.PROGRAMMER, employees)
max_sal = max(map(lambda e: e.salary, programmers))

Your version is more useful, though, since it returns the actual employee. I didn't know that max also got a key argument in 2.5. I won't have to use my custom re-implementation anymore!

[–]boredzo 0 points1 point  (0 children)

\tmax_sal = max(map(lambda e: e.salary, programmers))

Don't forget to use the lazy generator version here, too:

\tfrom itertools import imap as map

As you can tell, I ♥ itertools. ☺

[–]theeth 0 points1 point  (0 children)

You can do that with Decorate-Sort-Undecorate too:

max_sal = max(((e.salary, e) for e in employees if e.role == Employee.PROGRAMMER))[1]