Retrieving a specific object from a list?

Jeremiah Dodds jeremiah.dodds at gmail.com
Thu Apr 9 07:24:28 EDT 2009


On Thu, Apr 9, 2009 at 12:16 PM, andrew cooke <andrew at acooke.org> wrote:

> but when you need to access instances by more than one value (.bar and
> .baz) then typically that's a hard problem, and there's a trade-off
> somewhere.  you might find writing a special container that contains two
> dicts is useful.  if so, you might want to use weak references - see
> weakref module).
>
> all the above are relatively direct solutions.  in my experience this kind
> of issue often comes from not thinking at a high enough level about the
> algorithm - even though my third suggestion (deque) sounds rather obscure
> you may find that once you look at you algorithm more carefully it can be
> rewritten in that way.  i think i've seen this in my own code as i improve
> at integrating what might be more "functional" idioms into python in a
> "natural" (pythonic) way.
>
> andrew
>
>
Thanks, I have used a dict for doing what I was talking about in cases where
I only ever want to be able to access by one property of the objects, but as
you know, that doesn't work too well when I want to access by more than one
property.

It looks like I need to write a special class that acts as an iterable, and
as a map on values of (more-or-less) arbitrary properties of the objects
contained in it. I could probably also use with stepping back and looking at
my problem from a higher level to make sure I'm not barking up an entirely
wrong tree.

I'll take a look at weakref and dequeue, and see if they help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090409/5807ac01/attachment-0001.html>


More information about the Python-list mailing list