On Sep 30, 8:53 am, [EMAIL PROTECTED] 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"] -- http://mail.python.org/mailman/listinfo/python-list