string to integer problem

Rich Krauter rmkrauter at yahoo.com
Sun Feb 8 17:57:41 CET 2004


On Sun, 2004-02-08 at 11:29, Lol McBride wrote:
>I can't seem to get around how to return the data to it's original
>format
> i.e. the list with 6 integers - I have tried slicing the string and
> converting the charachters individually but then I run into trouble
when I
> have integers over two digits wide as I can't combine the two separate
> digits back into the original number.



>>> l = '(1,10,23,33,35,48)'
>>> [int(x) for x in l[1:-1].split(',')]
[1, 10, 23, 33, 35, 48]

Probably not the best way, but it seems to work.

Rich






More information about the Python-list mailing list