folks,
I want to modify list element with list comprehension. For example, if the element is negative, add 4 to it.
Thus the list
a = [1, -2 ,
Try this:
b = [x + 4 if x < 0 else x for x in a]
Or if you like map more than a list comprehension:
map
b = map(lambda x: x + 4 if x < 0 else x, a)