Wednesday, May 23, 2012

Summing over lists in python - is there a better way?

Is there a more sensible way of doing this? I want to make a new list by summing over the indices of a lot of other lists. I'm fairly new to programming and this seems like a very clunky method!



list1 = [1,2,3,4,5]
list2 = [1,1,1,4,1]
list3 = [1,22,3,1,5]
list4 = [1,2,5,4,5]
...
list100 = [4,5,6,7,8]

i = 0
while i < len(list1):
mynewlist[i] = list1[i]+list2[i]+list3[i]+list4[i]+...list100[i]
i = i+1




1 comment:

  1. What a good topic!I really appreciate your opinions.



    ----------------------------------------------
    Rc Helicopter|Rc Helicopters|Mini Rc Helicopter

    ReplyDelete