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


Groups > comp.lang.python > #59828

RE: Data structure question

From "Joseph L. Casale" <jcasale@activenetwerx.com>
Subject RE: Data structure question
Date 2013-11-18 02:43 +0000
References <59801e3624744664a94df7ce497b41ad@exch.activenetwerx.com> <CAPTjJmod8xax0DdW8_qE7+0ZzSDxvv83L+Z3ZiU=GkPDfWspZg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2818.1384742594.18130.python-list@python.org> (permalink)

Show all headers | View raw


> Not entirely sure I understand you, can you post an example?
> 
> 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

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


Thread

RE: Data structure question "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-11-18 02:43 +0000

csiph-web