Grouping the key-value pairs of a dictionary by the value with
which is equivalent (but faster) to a
lambda function like this:
Or sorting a list of tuples by the second element first the first element as secondary:
Instead of this
lambda-function that calls the method explicitly:
one could use a operator-function that does the same:
Operators as alternative to an infix operator
For every infix operator, e.g.
+ there is a
even though the main documentation states that for the arithmetic operators only numerical input is allowed it is possible:
See also: mapping from operation to operator function in the official Python documentation.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0