Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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; 'string.': 0.05; 'elegant': 0.07; 'already.': 0.09; 'strings.': 0.09; 'subject:question': 0.10; '(there': 0.16; 'dict': 0.16; 'example?': 0.16; 'fine.': 0.16; 'guys,': 0.16; 'lambda': 0.16; 'lookups.': 0.16; 'received:172.18.0': 0.16; 'string).': 0.16; 'subclass': 0.16; 'tuple': 0.16; 'index': 0.16; 'hey': 0.18; 'basically': 0.19; 'separate': 0.22; 'to:name:python-list@python.org': 0.22; 'entries': 0.24; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'gives': 0.31; 'getting': 0.31; 'thanks!': 0.32; 'entirely': 0.33; 'could': 0.34; 'something': 0.35; 'charset:us-ascii': 0.36; 'two': 0.37; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:unknown': 0.61; "you're": 0.61; 'name': 0.63 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=LEYBnznbHq3FhzR9LVFp1uvv3/Dy5AS/nulXTUPc3gs= c=1 sm=1 a=AgG5ixNBvo4A:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=tZ6OkIeOmUE8FkV5VsUA:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 From: "Joseph L. Casale" To: "python-list@python.org" Subject: RE: Data structure question Thread-Topic: Data structure question Thread-Index: Ac7kAEySLKcY6WXVTGCpW9ExahB98AAPj7wAAA3+maA= Date: Mon, 18 Nov 2013 02:43:09 +0000 References: <59801e3624744664a94df7ce497b41ad@exch.activenetwerx.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.18.0.201] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384742594 news.xs4all.nl 15894 [2001:888:2000:d::a6]:51087 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59828 > Not entirely sure I understand you, can you post an example? >=20 > If what you mean is that you need to locate the function (lambda) when > you know its corresponding strings, a dict will suit you just fine. > Either maintain two dicts for the two separate strings (eg if they're > "name" and "location" and you know whether you're looking up a name or > a location), or maintain a single dict with two entries per tuple (one > for each string). That gives you efficient and clean lookups. Hey guys, Basically I have several mappings like the following: 'string_a', 'string_b', lambda s: ... I need to be able to index a mapping (there are ~100) by either string_a or string_b and at one point with one of those strings I would pull the lambda or the other string. The important part is getting the row by either of the two strings. I know = I could just subclass dict and look it up the hardway with __missing__, just wondered if something elegant existed already. I may only know string_b and need string_a and the lambda. Thanks! jlc