Python·100 questions

How to quickly find minimum/maximum by key?

Answer
min(items, key=...).
max(items, key=...).
key can be lambda or attrgetter.
For dict: max(d, key=d.get).
More readable than manual loops.
Was this answer helpful?

More questions in this topic

Related questions from other topics