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:
- Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four
- Convert a 3D array to RGB valued array [closed]
- How can I calculate a list modulo a numer in python?
- How to read video stream as input in OpenCV python?
- How to select a drop-down menu value with Selenium using Python?
- How do I get a list of locally installed Python modules?
- Calling a python script with input within a python script using subprocess
- Stacked Bar Chart with Centered Labels
- Add text to Existing PDF using Python
- Django Passing Custom Form Parameters to Formset
- How do I count occurrence of unique values inside a list
- how to run python script without typing ‘python …’
- Getting rid of console output when freezing Python programs using Pyinstaller
- What do I use for a max-heap implementation in Python?
- How to sort and remove duplicates from Python list? [duplicate]
- Case insensitive dictionary
- Python OpenCV load image from byte string
- Sorting a dictionary with lists as values, according to an element from the list
- How to check if the current time is in range in python?
- Merge several Python dictionaries
- set of list of lists in python
- Make Anaconda’s tkinter aware of system fonts or install new fonts for Anaconda
- stop tkinter window from freezing while program is sleeping
- What’s the difference between Docker and Python virtualenv?
- How to hash a large object (dataset) in Python?
- How to create a legend for 3D bar in matplotlib?
- Python lazy list
- Issue with regex backreference in Python
- Python “decimal” package gives wrong results
- What difference between pickle and _pickle in python 3?