Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/writing/gotchas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ its arguments by using a default arg like so:
def create_multipliers():
return [lambda x, i=i : i * x for i in range(5)]

Alternatively, you can use the functools.partial function:

.. code-block:: python

from functools import partial
from operator import mul

def create_multipliers():
return [partial(mul, i) for i in range(5)]

When the Gotcha Isn't a Gotcha
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down