One option is a list comprehension:
[add(x, 2) for x in [1, 2, 3]]
More options:
a = [1, 2, 3]
import functools
map(functools.partial(add, y=2), a)
import itertools
map(add, a, itertools.repeat(2, len(a)))
More Related Contents:
- Need a python module for numerical and scientific computing other than NumPy and SciPy
- Is there a way to ordinate numbers in a list?
- Pillow installed, but getting “no module named pillow”
- Extract the data and modify an existing excel with openpyxl
- Adding a scrollbar to a group of widgets in Tkinter
- A non-blocking read on a subprocess.PIPE in Python
- How to drop rows of Pandas DataFrame whose value in a certain column is NaN
- How can I filter lines on load in Pandas read_csv function?
- “Cannot open include file: ‘config-win.h’: No such file or directory” while installing mysql-python
- How would I access variables from one class to another?
- adding directory to sys.path /PYTHONPATH
- VSCode — how to set working directory for debugging a Python program
- How to block calls to print?
- How to detect lines in OpenCV?
- Efficient way to add spaces between characters in a string
- What is different between all these OpenCV Python interfaces?
- IOError: [Errno 32] Broken pipe when piping: `prog.py | othercmd`
- How to implement sql coalesce in pandas
- Get path from open file in Python
- Matplotlib runs out of memory when plotting in a loop
- Python Math – TypeError: ‘NoneType’ object is not subscriptable
- How do I create a multiline Python string with inline variables?
- psycopg2 installation error – Library not loaded: libssl.dylib
- How to check if a given number is a power of two?
- Using Windows Python from Cygwin
- How can I insert NULL data into MySQL database with Python?
- How to do a scatter plot with empty circles in Python?
- python function default parameter is evaluated only once? [duplicate]
- Load CSV to Pandas MultiIndex DataFrame
- Decorator error: NoneType object is not callable