What would be an elegant way to map a two parameter lambda function to a list of values where the first parameter is constant and the second is taken from a list?
Example:
lambda x,y: x+y
x='a'
y=['2','4','8','16']
expected result:
['a2','a4','a8','a16']
Notes:
- This is just an example, the actual lambda function is more complicated
- Assume I can’t use list comprehension
You can use
itertools.starmapand you get your desired output.
BTW, both
itertools.imapand Python3’smapwill accept the following:The default Python2’s
mapwill not stop at the end ofyand will insertNones…But a comprehension is much better