a.split(',')
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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.
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
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
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
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
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
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
10 matches
Mail list logo