Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97254

Re: Question about regular expression

Path csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Question': 0.05; '(1,': 0.09; '0),': 0.09; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'output': 0.13; 'everyone,': 0.15; 'result.': 0.15; '4),': 0.16; 'expressions,': 0.16; 'only)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'wrote:': 0.16; 'string': 0.17; 'integer': 0.18; '>>>': 0.20; 'not,': 0.22; 'form:': 0.22; 'tuples': 0.22; 'am,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'format,': 0.27; "skip:' 10": 0.28; 'regular': 0.29; 'dictionary': 0.29; 'spaces': 0.29; 'there!': 0.29; "i'd": 0.31; 'guess': 0.31; 'possibly': 0.32; 'problem': 0.33; 'surely': 0.33; 'values.': 0.33; 'functions.': 0.35; 'problem.': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'starting': 0.37; 'drop': 0.38; 'names': 0.38; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; 'between': 0.65; 'groups.': 0.72; 'received:12': 0.81
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Emile van Sebille <emile@fenx.com>
Subject Re: Question about regular expression
Date Wed, 30 Sep 2015 11:50:12 -0700
References <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host www.westernstatesglass.com
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
In-Reply-To <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.274.1443639036.28679.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443639036 news.xs4all.nl 23734 [2001:888:2000:d::a6]:40799
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97254

Show key headers only | View raw


On 9/30/2015 11:34 AM, massi_srb@msn.com wrote:
> Hi everyone,
>
> firstly the description of my problem. I have a string in the following form:
>
> s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..."
>
> that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing 1 or 2 integer values. Blanks can be placed between names and tuples or not, but they surely are placed beween two groups. I would like to process this string in order to get a dictionary like this:
>
> d = {
>      "name1":(0, 0),
>      "name2":(1, 0),
>      "name3":(0, 0),
>      "name4":(1, 4),
>      "name5":(2, 0),
> }
>
> I guess this problem can be tackled with regular expressions,

Stop there!  :)

I'd use string functions.  If you can control the string output to drop 
the spaces and always output in namex(a,b)<space>namey(c,d)... format, 
try starting with

 >>> "name1 name2(1) name3 name4(1,4) name5(2)".split()
['name1', 'name2(1)', 'name3', 'name4(1,4)', 'name5(2)']

then create the dict from the result.

Emile

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about regular expression massi_srb@msn.com - 2015-09-30 11:34 -0700
  Re: Question about regular expression Emile van Sebille <emile@fenx.com> - 2015-09-30 11:50 -0700
  Re: Question about regular expression Tim Chase <python.list@tim.thechases.com> - 2015-09-30 14:20 -0500
  Re: Question about regular expression Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-30 23:30 +0000
    Re: Question about regular expression Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-02 18:25 +0000
  Re: Question about regular expression Emile van Sebille <emile@fenx.com> - 2015-09-30 20:58 -0700
  Re: Question about regular expression Tim Chase <python.list@tim.thechases.com> - 2015-10-01 07:39 -0500
  Re: Question about regular expression Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-10-01 15:53 +0000
    Re: Question about regular expression Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-01 21:41 +0000
  Re: Question about regular expression Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-01 21:31 +0000

csiph-web