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


Groups > comp.lang.python > #21070

Re: Help needed: dynamically pull data from different levels of a dict

Path csiph.com!aioe.org!news.le-studio75.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:verizon.net': 0.07; 'skip:{ 20': 0.07; 'terry': 0.07; 'dict': 0.09; 'dynamically': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "'',": 0.16; 'reedy': 0.16; 'simplified': 0.16; 'subject: \n ': 0.16; 'utc': 0.16; 'val': 0.16; 'subject:Help': 0.17; 'wrote:': 0.18; 'converted': 0.18; 'skip:[ 20': 0.19; 'jan': 0.19; 'header:In- Reply-To:1': 0.22; 'pieces': 0.23; "skip:' 40": 0.23; 'subject:data': 0.25; 'code': 0.26; 'figure': 0.26; 'bit': 0.28; "i'm": 0.28; "skip:' 30": 0.29; "skip:' 10": 0.29; 'problem': 0.29; 'print': 0.29; 'pm,': 0.29; "i've": 0.32; 'thanks': 0.32; 'actual': 0.32; "can't": 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'header:X-Complaints-To:1': 0.34; 'problem.': 0.35; 'to:addr :python-list': 0.35; 'something': 0.35; 'received:org': 0.36; 'like,': 0.37; 'pull': 0.37; 'some': 0.38; 'data': 0.38; 'open': 0.38; "i'd": 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'life,': 0.64; 'below.': 0.64; "'2',": 0.84; '02:27': 0.84; '11:04': 0.84; 'subject:different': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Help needed: dynamically pull data from different levels of a dict
Date Thu, 01 Mar 2012 00:35:00 -0500
References <BLU150-W5569CF6B8809704AB12EC8986C0@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <BLU150-W5569CF6B8809704AB12EC8986C0@phx.gbl>
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.314.1330580116.3037.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330580116 news.xs4all.nl 6980 [2001:888:2000:d::a6]:33923
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21070

Show key headers only | View raw


On 2/29/2012 11:04 PM, Peter Rubenstein wrote:

> I'd appreciate a bit of help on this problem.  I have some data that I've converted to a dict and I want to pull out individual pieces of it.
>
> Simplified version--
> a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } }
>
> I'd like to be able to code something like:
>
> data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed:        answer=extract_from(a,val)        print answer
>
> And get:abcde
>
> Problem is I can't figure out what extract_from would look like, such that it would proceed dynamically down to the right level.  I'm open to the possibility that I'm not approaching this the right way.
> If it helps, one member of my actual dict quoted below.  So in real life, something likedata_needed=['name','active-defects', 'admin-status:format', 'description', 'traffic-statistics:input-bps']etc.
>
> Thanks in advance,Peter
>
> { 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': ''}},  'active-defects': {'interface-alarms': {'alarm-not-present': ''}},  'admin-status': {'_text': 'up', 'format': 'Enabled'},  'current-physical-address': '00:1f:12:c0:e8:00',  'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:',  'hardware-physical-address': '00:1f:12:c0:e8:00',  'if-config-flags': {'iff-snmp-traps': '', 'internal-flags': '0x4000'},  'if-device-flags': {'ifdf-present': '', 'ifdf-running': ''},  'if-flow-control': 'enabled',  'if-media-flags': {'ifmf-none': ''},  'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC (92w3d 02:27 ago)',   'seconds': '55909644'},  'l2pt-error': 'none',  'link-level-type': 'Ethernet',  'local-index': '171',  'logical-interface': {'address-family': [{'address-family-flags': {'ifff-no-redirects': '',      'internal-flags': '0x0'},     'address-family-name': 'inet',     'interface-address': {'ifa-destination': '207.46.43.2/31',      'ifa-flags': {'ifa
f-current-preferred': '', 'ifaf-current-primary': ''},      'ifa-local': '207.46.43.2'},     'mtu': '9178'},    {'address-family-flags': {'ifff-mtu-user-conf': '',      'internal-flags': '0x10000000'},     'address-family-name': 'mpls',     'mtu': '9174'},    {'address-family-flags': {'ifff-none': ''},     'address-family-name': 'multiservice',     'mtu': 'Unlimited'}],   'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:',   'encapsulation': 'ENET2',   'if-config-flags': {'iff-snmp-traps': ''},   'local-index': '67',   'name': 'ge-0/0/0.0',   'snmp-index': '117',   'traffic-statistics': {'input-packets': '46367422526659',    'output-packets': '35670513402384',    'style': 'brief'}},  'loopback': 'disabled',  'mtu': '9192',  'name': 'ge-0/0/0',  'oper-status': 'up',  'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': '8',   'physical-interface-cos-use-max-queues': '8'},  'snmp-index': '116',  'source-filtering': 'disabled',  'speed': '10Gbps',  't
raffic-statistics': {'input-bps': '4104358720',   'input-pps': '1059450',   'output-bps': '2323588888',   'output-pps': '537816',   'style': 'brief'}},} 		 	   		


-- 
Terry Jan Reedy

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


Thread

Re: Help needed: dynamically pull data from different levels of a dict Terry Reedy <tjreedy@udel.edu> - 2012-03-01 00:35 -0500

csiph-web