-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,740
  • 10
  • 53
  • 80
AK9309
  • 761
  • 3
  • 13
  • 33

2 Answers2

-3
>>> import re
>>> list(map(int, re.split(r'\s+', '23 22 55 67')))
[23, 22, 55, 67]
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
-3
line_str = "23 22 55 67".split(" ")
numbers = []
for n in line_str:
    numbers.append(int(n))

print numbers
f.rodrigues
  • 3,499
  • 6
  • 26
  • 62