Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75915 > unrolled thread
| Started by | luofeiyu <elearn2014@gmail.com> |
|---|---|
| First post | 2014-08-09 07:25 -0700 |
| Last post | 2014-08-09 07:25 -0700 |
| 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? luofeiyu <elearn2014@gmail.com> - 2014-08-09 07:25 -0700
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-09 07:25 -0700 |
| Subject | Re: more simple to split the string? |
| Message-ID | <mailman.12771.1407540340.18130.python-list@python.org> |
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
>>> str.split(" ")
['(\\HasNoChildren', '\\Junk)', '"/"', '"[Gmail]/&V4NXPpCuTvY-"']
>>>
it can be split into four parts,you can see.
On 8/8/2014 1:43 AM, Mark Lawrence wrote:
> 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-']
>
Back to top | Article view | comp.lang.python
csiph-web