Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16119
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <arnodel@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.038 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'way:': 0.05; 'comprises': 0.07; 'subject:String': 0.16; 'cc:addr:python-list': 0.16; 'subject:question': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'string': 0.24; 'cc:2**0': 0.24; '"this': 0.24; 'message-id:@mail.gmail.com': 0.28; 'pass': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'splitting': 0.30; 'everyone,': 0.32; 'received:209.85.212': 0.34; 'parse': 0.34; 'received:google.com': 0.37; 'received:209.85': 0.38; 'else': 0.39; 'received:209': 0.40; '2011': 0.61; 'quotations': 0.84; 'spaces.': 0.84; 'substrings': 0.84; 'to:addr:msn.com': 0.96 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=yvLHYzOyGNP92E7aTdJ4VSfjGlwdCsVJcxPPWe0oOfI=; b=lpYO7XiEIp2Sw05pkZ2QKkgv6lB0TkuYbxYFj4fzRGu7knNk85p8m4Al6u74m5rpuY Ddm7FoJioDBaPklfY1BXEyswHXSAxHWV2SeyZDDz6g0HCrrP9UfECxjmx4XS/M3hcofM U/sIWV0DWytWW+dwH34BgE1HlJvHsbay423I8= |
| MIME-Version | 1.0 |
| In-Reply-To | <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com> |
| References | <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com> |
| Date | Wed, 23 Nov 2011 17:40:37 +0000 |
| Subject | Re: String splitting by spaces question |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| To | Massi <massi_srb@msn.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2976.1322070040.27778.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1322070040 news.xs4all.nl 6903 [2001:888:2000:d::a6]:43286 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16119 |
Show key headers only | View raw
On 23 November 2011 17:10, Massi <massi_srb@msn.com> wrote:
> Hi everyone,
>
> I have to parse a string and splitting it by spaces. The problem is
> that the string can include substrings comprises by quotations which
> must mantain the spaces. What I need is to pass from a string like:
>
> This is an 'example string'
>
> to the following vector:
You mean "list"
> ["This", "is", "an", "example string"]
>
Here's a way:
>>> s = "This is an 'example string' with 'quotes again'"
>>> [x for i, p in enumerate(s.split("'")) for x in ([p] if i%2 else p.split())]
['This', 'is', 'an', 'example string', 'with', 'quotes again']
--
Arnaud
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
String splitting by spaces question Massi <massi_srb@msn.com> - 2011-11-23 09:10 -0800
RE: String splitting by spaces question "Alemu Tadesse" <atadesse@sunedison.com> - 2011-11-23 11:31 -0600
Re: String splitting by spaces question Arnaud Delobelle <arnodel@gmail.com> - 2011-11-23 17:40 +0000
Re: String splitting by spaces question Nick Dokos <nicholas.dokos@hp.com> - 2011-11-23 12:51 -0500
Re: String splitting by spaces question Miki Tebeka <miki.tebeka@gmail.com> - 2011-11-23 12:40 -0800
Re: String splitting by spaces question Phil Rist <Phil_member@newsguy.com> - 2011-11-23 16:20 -0800
Re: String splitting by spaces question DevPlayer <devplayer@gmail.com> - 2011-11-23 19:53 -0800
csiph-web