split() with a separator set
Mikael Olofsson
mikael at isy.liu.se
Mon Jun 19 11:40:23 EDT 2000
On 19-Jun-00 Igor V. Rafienko wrote:
> # input looks like this: 'foo:bar|baz/zot'
> # I want [ 'foo', 'bar', 'baz', 'zot' ]
> string.split( src, ":|/" )
>
> doesn't work.
Igor!
Oleg just gave you a solution using re:s. If you try to avoid these
animals, like I do, you could do the following:
seps = ':|/'
mystring = 'foo:bar|baz/zot'
newstring = string.join(map(lambda x, seps=seps:(x+seps[0])[x in seps],a),'')
result = string.split(newstring,seps[0])
Good luck!
/Mikael
-----------------------------------------------------------------------
E-Mail: Mikael Olofsson <mikael at isy.liu.se>
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date: 19-Jun-00
Time: 17:34:03
/"\
\ / ASCII Ribbon Campaign
X Against HTML Mail
/ \
This message was sent by XF-Mail.
-----------------------------------------------------------------------
More information about the Python-list
mailing list