Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75934 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2014-08-09 09:15 +0200 |
| Last post | 2014-08-09 09:15 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: more simple to split the string? Peter Otten <__peter__@web.de> - 2014-08-09 09:15 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-08-09 09:15 +0200 |
| Subject | Re: more simple to split the string? |
| Message-ID | <mailman.12785.1407568566.18130.python-list@python.org> |
elearn wrote:
> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
> x=str.split(' "')
> [i.replace('"','') for i in x]
> ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-']
>
> x.strip(" ") will create four parts.
>
> is there more simple to do that ?
Here's another way:
>>> s = '(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
>>> s.replace("(", '"').replace(")", '"').split('"')[1::2]
['\\HasNoChildren \\Junk', '/', '[Gmail]/&V4NXPpCuTvY-']
But you should rather worry about correctness. Can '"' occur inside the
parentheses and vice versa? Is there a way to escape '"'? Can parentheses be
nested? Etc.
The example is not sufficient to specify the problem.
Back to top | Article view | comp.lang.python
csiph-web