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


Groups > comp.lang.python > #59828 > unrolled thread

RE: Data structure question

Started by"Joseph L. Casale" <jcasale@activenetwerx.com>
First post2013-11-18 02:43 +0000
Last post2013-11-18 02:43 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#59828 — RE: Data structure question

From"Joseph L. Casale" <jcasale@activenetwerx.com>
Date2013-11-18 02:43 +0000
SubjectRE: Data structure question
Message-ID<mailman.2818.1384742594.18130.python-list@python.org>
> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web