Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'parser': 0.07; 'happen,': 0.09; 'happen?': 0.09; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; 'blocks': 0.16; 'dictionaries': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parser.': 0.16; 'splitting': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'split': 0.19; 'feb': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'fairly': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; '(maybe': 0.31; 'basic': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'pm,': 0.38; 'how': 0.40; 'name': 0.63; 'more': 0.64; 'here': 0.66; '2015': 0.84; 'absolutely': 0.87; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rdEPXD5iDsSn8hbmLRSMjcn+ODKYC8vVkRiPwCQr0mI=; b=BZVpOn150c9bsVHcPW+p4DeFK9hTbspPmWqnx7tBPyQ/yFBNb+FIfmSAf9y822gZOL Rk5aW9Lv0Ms+Kn8dj5sa28ohByn1KzW8C0onn22hU3QQq1Z4sTfXhj9QjUvrxKw2TIBM pjm6th1cTUNFLuPHGqrp1+0MsfC7oi/9vMSoEAtC6T75PIpReTAsPFVt5BZHAuA10B5a R15Q1RUerxZpotQWUuxljfKo69aLIyNhCNTgaLKsaKdHlIH3DIFsjqQUkuts87kZJwfa J0D7aqub1EEl2bu1785iyid03dH6PM1Tm/3geOuWlGrkpq0vgFcwxA9bsdtmSYeygixR bI1Q== MIME-Version: 1.0 X-Received: by 10.50.131.196 with SMTP id oo4mr691251igb.2.1424232965098; Tue, 17 Feb 2015 20:16:05 -0800 (PST) In-Reply-To: References: Date: Wed, 18 Feb 2015 15:16:05 +1100 Subject: Re: Noob Parsing question From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424232968 news.xs4all.nl 2855 [2001:888:2000:d::a6]:37271 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 986404431 X-Received-Bytes: 3730 Xref: csiph.com comp.lang.python:85767 On Wed, Feb 18, 2015 at 3:07 PM, wrote: > Given > > data = '{[][]}' > > How can I efficiently get dictionaries for each of the data blocks framed by <> ? > > Thanks for any help The question here is: What _can't_ happen? For instance, what happens if Fred's name contains a greater-than symbol, or a caret? If those absolutely cannot happen, your parser can be fairly straight-forward. Just put together some basic splitting (maybe a regex), and then split on the caret inside that. Otherwise, you may need a more stateful parser. ChrisA