-3

I have a string that goes like this:

data = "2, 32, 56, 87, 45, 98, 1"

I am trying to strip the commas and spaces out, and then parse the string into integers. I have tried to remove the commas and spaces using if spaces, but the problem I keep getting is that I get this:

[2, 3, 2, 5, 6, 8, 7, 4, 5, 9, 8, 1]

is there anyway to get a list like this:

[2, 32, 56, 87, 45, 98, 1]
  • 1
    Does this answer your question? [How to convert a string of space- and comma- separated numbers into a list of int?](https://stackoverflow.com/questions/19334374/python-converting-a-string-of-numbers-into-a-list-of-int) – Gino Mempin Aug 27 '21 at 21:30

1 Answers1

2

You could do it the following way.

example:

[int(k) for k in data.split(',')]
Roxy
  • 1,015
  • 7
  • 20