B
bonono
Hi,
are there a strtok equivalent in python ? str.split() only takes single
seperator.
are there a strtok equivalent in python ? str.split() only takes single
seperator.
are there a strtok equivalent in python ? str.split() only takes single
seperator.
['breakfast', 'spam', 'egg', 'bacon']>>> s = "breakfast=spam+egg-bacon"
>>> import re
>>> re.split("[-+=]", s)
['breakfast', 'spam', 'egg', 'bacon']>>> re.split("[" + re.escape("-+=") + "]", s)
Fredrik said:are there a strtok equivalent in python ? str.split() only takes single
seperator.
use a regular expression split with a character group:
['breakfast', 'spam', 'egg', 'bacon']s = "breakfast=spam+egg-bacon"
import re
re.split("[-+=]", s)
to deal with an arbitrary set of delimiting characters without having to
bother with RE syntax, use re.escape:
['breakfast', 'spam', 'egg', 'bacon']re.split("[" + re.escape("-+=") + "]", s)
</F>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.