Python adding elements from string

Posted by owca on Stack Overflow See other posts from Stack Overflow or by owca
Published on 2010-05-26T00:14:52Z Indexed on 2010/05/26 0:21 UTC
Read the original article Hit count: 519

Filed under:
|
|
|

I have a string like this "1 1 3 2 1 1 1 2 1 1 1 1 1 1 1 1,5 0,33 0,66 1 0,33 0,66 1 1 2 1 1 2 1 1 2 0,5 0,66 2 1 2 1 1 1 0 1".

How to add elements to each other in python ?

I've tried :

list = []
for x in str.replace(' ', ''):
    list.append(x)
sum = 0
for y in list:
    sum = sum + double(x)

but I'm getting errors constantly.

© Stack Overflow or respective owner

Related posts about python

Related posts about string