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 , 2]
will be converted to
a = [1, 2, 2]
The following code works, but i am wondering if there is a better way to do it?
Thanks.
for i in range(len(a)):
if a[i]<0:
a[i] += 4
1 Answer