Re: s.split() on multiple separators
- From: William James <w_a_x_man@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 11:27:32 -0700
On Sep 30, 8:53 am, mrk...@xxxxxxxxx wrote:
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:
c=' abcde abc cba fdsa bcd '.split()
dels='ce '
for j in dels:
cp=[]
for i in xrange(0,len(c)-1):
cp.extend(c[i].split(j))
c=cp
c
['ab', 'd', '', 'ab', '', '']
But. Surely there is a more Pythonic way to do this?
I cannot do this:
for i in dels:
c=[x.split(i) for x in c]
because x.split(i) is a list.
E:\Ruby>irb
irb(main):001:0> ' abcde abc cba fdsa bcd '.split(/[ce ]/)
=> ["", "ab", "d", "", "ab", "", "", "ba", "fdsa", "b", "d"]
.
- Follow-Ups:
- Re: s.split() on multiple separators
- From: mrkafk
- Re: s.split() on multiple separators
- References:
- s.split() on multiple separators
- From: mrkafk
- s.split() on multiple separators
- Prev by Date: Re: code for number guessing by computer
- Next by Date: Re: Python and SSL
- Previous by thread: Re: s.split() on multiple separators
- Next by thread: Re: s.split() on multiple separators
- Index(es):