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

2006-11-23 Thread Tim Williams
On 23/11/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Tim Williams wrote: > > > and the use of a list comprehension is pretty silly to, given that you want > to apply the same *function* to all items, and don't really need to look > it up for every item: > > map(int, s.split(',')) Haha

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

2006-11-23 Thread Fredrik Lundh
Tim Williams wrote: >> It is a dangerous solution if your data is coming from an untrusted source. >> >> >>> s = "10, 20, 30" >> >>> L = [x.strip() for x in s.split(',')] >> >>> L >> ['10', '20', '30'] >> >>> L = [int(x) for x in L] >> >>> L >> [10, 20, 30] >> >> Or, as a one liner: [int(x.strip(

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

2006-11-23 Thread Tim Williams
On 23/11/06, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 23 Nov 2006 03:13:10 -0800, Daniel Austria wrote: > > > 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) >

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

2006-11-23 Thread John Machin
Daniel Austria wrote: > 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 Most people share your opinion. Try this: | >>> strg = "10, 20

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

2006-11-23 Thread Steven D'Aprano
On Thu, 23 Nov 2006 03:13:10 -0800, Daniel Austria wrote: > 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 It is a dangerous solu

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

2006-11-23 Thread Tech
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

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

2006-11-23 Thread Tim Williams
On 23 Nov 2006 03:13:10 -0800, Daniel Austria <[EMAIL PROTECTED]> wrote: > 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 > Not nice, e

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

2006-11-23 Thread Daniel Austria
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 -- http://mail.python.org/mailman/listinfo/python-list