Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'syntax': 0.04; 'lst': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'dict': 0.16; 'dictionary.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'instead:': 0.16; 'subject:accessing': 0.16; 'subject:array': 0.16; 'subject:dictionaries': 0.16; 'tuple': 0.16; 'tuple,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'skip:{ 20': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'array': 0.29; 'message- id:@mail.gmail.com': 0.30; 'received:google.com': 0.35; 'list': 0.37; 'pm,': 0.38; 'most': 0.60; 'hope': 0.61; 'sam': 0.68; '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=tqLLBs4zJtLO7xEbQqH/tBCiMU8mof/jqDSdVo/F/+o=; b=Y3NS4aOBicHuG5Kwcawp1SBcAqD/vtSSYOBh+OGWxppU3qpMO5RKQfMg6sS0ZO946k aDlpyHwExQEOVCPP1j0NAmGwaJ35uzgdwtCOUXL3RzTLYgUOCP1PlifmWNyeRmAy+bJy fJJhV5a8T2MRxqL8yQyl9BPG76FSjwb1GfTvinzo22NFnGGZ/uKbSNNn3yT4omWGdnPm 7G00HsZYUfjvjUQXvNGQWP+9owmf1i8k/Sml44PrRF0JYnGeFn7/HJinDTyz38h0XIet qifba5TH89mThDCgGWkVSAVXbOKaSTWzM2J2jxx5swy8/tECac8FxrdVI7wNO29/DMjG OQlQ== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr8697503pab.43.1389865711550; Thu, 16 Jan 2014 01:48:31 -0800 (PST) In-Reply-To: References: Date: Thu, 16 Jan 2014 20:48:31 +1100 Subject: Re: Building and accessing an array of dictionaries 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389865714 news.xs4all.nl 2907 [2001:888:2000:d::a6]:47518 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64068 On Thu, Jan 16, 2014 at 8:41 PM, Sam wrote: > I would like to build an array of dictionaries. Most of the dictionary example on the net are for single dictionary. > > dict = {'a':'a','b':'b','c':'c'} > dict2 = {'a':'a','b':'b','c':'c'} > dict3 = {'a':'a','b':'b','c':'c'} > > arr = (dict,dict2,dict3) > > What is the syntax to access the value of dict3->'a'? Technically, that's a tuple of dictionaries, and you may want to use a list instead: lst = [dict, dict2, dict3] Like any other list or tuple, you can reference them by their indices: lst[2] is dict3 lst[2]['a'] is dict3['a'] Hope that helps! ChrisA