-4

I want to separate numbers in a string so I would be able to do a calculation with the numbers.

Example:

line_str = "23 22 55 67"   

So far I have used:

for char in line_str:
print (char)

I don't know how to be able to make do a calculation with each number.

And I believe I can't just write number_int = int(char) and continue with number_int.

J0e3gan
  • 8,570
  • 9
  • 52
  • 78
AK9309
  • 731
  • 3
  • 13
  • 32

2 Answers2

-3
>>> import re
>>> list(map(int, re.split(r'\s+', '23 22 55 67')))
[23, 22, 55, 67]
Chris Martin
  • 29,484
  • 8
  • 71
  • 131
-3
line_str = "23 22 55 67".split(" ")
numbers = []
for n in line_str:
    numbers.append(int(n))

print numbers
f.rodrigues
  • 3,375
  • 6
  • 23
  • 59