s.split() on multiple separators
- From: mrkafk@xxxxxxxxx
- Date: Sun, 30 Sep 2007 06:53:14 -0700
Hello everyone,
OK, so I want to split a string c into words using several different
separators from a list (dels).
I can do this the following C-like way:
cp=[]c=' abcde abc cba fdsa bcd '.split()
dels='ce '
for j in dels:
for i in xrange(0,len(c)-1):
cp.extend(c[i].split(j))
c=cp
['ab', 'd', '', 'ab', '', '']c
But. Surely there is a more Pythonic way to do this?
I cannot do this:
c=[x.split(i) for x in c]for i in dels:
because x.split(i) is a list.
.
- Follow-Ups:
- Re: s.split() on multiple separators
- From: William James
- Re: s.split() on multiple separators
- From: Bryan Olson
- Re: s.split() on multiple separators
- From: Tim Chase
- Re: s.split() on multiple separators
- From: Francesco Guerrieri
- Re: s.split() on multiple separators
- From: Francesco Guerrieri
- Re: s.split() on multiple separators
- Prev by Date: Re: Can you please give me some advice?
- Next by Date: notify when process finishes (on unix)
- Previous by thread: Re: which language allows you to change an argument's value?
- Next by thread: Re: s.split() on multiple separators
- Index(es):