Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75870
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: more simple to split the string? |
| Date | 2014-08-08 09:43 +0100 |
| References | <53E4186A.5020201@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12742.1407487434.18130.python-list@python.org> (permalink) |
On 08/08/2014 01:23, elearn wrote:
> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
First up it's not usually a good idea to override the builtin name str.
> x=str.split(' "')
> [i.replace('"','') for i in x]
> ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-']
>
> x.strip(" ") will create four parts.
I assume you meant x=str.split(" ") ? Even so I don't see how you can
get four parts so please explain.
>
> is there more simple to do that ?
No loop needed that I can see.
>>> oldstr='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"';oldstr
'(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
>>> newstr=oldstr.replace('"', '');newstr
'(\\HasNoChildren \\Junk) / [Gmail]/&V4NXPpCuTvY-'
>>> substrings=newstr.split();substrings
['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-']
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: more simple to split the string? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-08 09:43 +0100
csiph-web