Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python array_walk() alternative

Tags:

python

i have a list that looks like this:

list = [1,2,3,4]

I would like to add 12 to each value. In PHP you can use array_walk to process each item in the array. Is there a similar function or easier way than doing a for loop such as:

for i in list:

Thanks

like image 786
anon Avatar asked Dec 03 '22 01:12

anon


1 Answers

Use list comprehensions. Try this:

list = [i+12 for i in list]
like image 169
AJ. Avatar answered Dec 07 '22 23:12

AJ.