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.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to