Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59828 > unrolled thread
| Started by | "Joseph L. Casale" <jcasale@activenetwerx.com> |
|---|---|
| First post | 2013-11-18 02:43 +0000 |
| Last post | 2013-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.
RE: Data structure question "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-11-18 02:43 +0000
| From | "Joseph L. Casale" <jcasale@activenetwerx.com> |
|---|---|
| Date | 2013-11-18 02:43 +0000 |
| Subject | RE: 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
Back to top | Article view | comp.lang.python
csiph-web