On Fri, 15 Oct 2010 05:19:57 am Sander Sweers wrote:

> So you want convert string u'1,2,3,4' to a list of ints [1,2,3,4]?
> Then the below will work.
>
> [int(n) for n in u'1,2,3,4'.replace(',', '')]

That will break if you have u'100,2,3,4'.

Better is:


>>> s = '1, 200 , -3,4'  # or whatever
>>> [int(x) for x in s.split(',')]
[1, 200, -3, 4]




-- 
Steven D'Aprano
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to