Re: Simple question to split

2006-11-10 Thread cppasm
a.split(',') -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple question to split

2006-11-09 Thread Tiefeng Wu
Matthias Winterland wrote: > Hi, > > I have a simple question. When I read in a string like: > a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a > single split-call? > > Thx, > Matthias Sorry, I didn't notice there are spaces between 5 6 7 :{P here is new code: >>> a = "1,2,3

Re: Simple question to split

2006-11-09 Thread Tiefeng Wu
Matthias Winterland wrote: > Hi, > > I have a simple question. When I read in a string like: > a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a > single split-call? > > Thx, > Matthias Maybe like this: >>> a = "1,2,3,4,5,6,7,3,4" >>> l = [int(n) for n in a.split(',')] >>> l

Re: Simple question to split

2006-11-09 Thread John Machin
Matthias Winterland wrote: > Hi, > > I have a simple question. When I read in a string like: > a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a > single split-call? > Using str method split, no -- as documented [hint!], it provides only a single separator argument. Using re.

Re: Simple question to split

2006-11-09 Thread faulkner
def splits(seq, cs): if not cs: return seq elif isinstance(seq, str): return splits(seq.split(cs[0]), cs[1:]) else: return splits(sum([elem.split(cs[0]) for elem in seq], []), cs[1:]) or a = re.split('(\ |\,)', a) a.remove(' ') a.remove(',') Matthias Winterland wrote: > Hi, > > I have

Re: Simple question to split

2006-11-09 Thread Georg Brandl
Diez B. Roggisch schrieb: > Diez B. Roggisch schrieb: >> Matthias Winterland schrieb: >>> Hi, >>> >>> I have a simple question. When I read in a string like: >>> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a >>> single split-call? >> >> Nope. But you could replace the com

Re: Simple question to split

2006-11-09 Thread Diez B. Roggisch
Diez B. Roggisch schrieb: > Matthias Winterland schrieb: >> Hi, >> >> I have a simple question. When I read in a string like: >> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a >> single split-call? > > Nope. But you could replace the commas with spaces, and then split. Or

Re: Simple question to split

2006-11-09 Thread Diez B. Roggisch
Matthias Winterland schrieb: > Hi, > > I have a simple question. When I read in a string like: > a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a > single split-call? Nope. But you could replace the commas with spaces, and then split. Diez -- http://mail.python.org/mailma

Re: Simple question to split

2006-11-09 Thread Dan Lenski
Yep, use regular expressions! For example, use the regular expression r',|\s+' to split on either (a) any amount of whitespace or (b) a single comma. Try this: import re a='1,2,3,4,5 6 7,3,4' print re.split(r',|\s+*', a) Matthias Winterland wrote: > Hi, > > I have a simple question. When I read

Re: Simple question to split

2006-11-09 Thread Robert Kern
Matthias Winterland wrote: > Hi, > > I have a simple question. When I read in a string like: > a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a > single split-call? You can't get what you want with a single method call. You can do it with a single call to .split() if you pr