"10, 20, 30" to [10, 20, 30]

Tech tech at axetic.com
Thu Nov 23 12:23:29 CET 2006


Daniel Austria a écrit :
> Sorry,
> 
> how can i convert a string like "10, 20, 30" to a list [10, 20, 30]
> 
> what i can do is:
> 
> s = "10, 20, 30"
> tmp = '[' + s + ']'
> l = eval(tmp)
> 
> but in my opinion this is not a nice solution
> 
> 
> daniel
> 

If you're sure that there's only ints
l = [int(item) for item in s.split(', ')]

Yannick



More information about the Python-list mailing list