accessing an object instance by only having one of its attribute values

Stargaming stargaming at
Sun Jul 8 21:02:46 CEST 2007

feli.hp at wrote:
> Hello all,
> Imaybe someone can help me with this question.
> Is there a direct way of accessing an object instance, if all I know
> is the value of one of its attributes?
> The object is part of a list of objects, and I would like to pick the
> object directly by using this attribute value, instead of going
> through the list and checking if each objects attribute value is the
> one I am looking for.
> Thank you in advance

Okay, imagine you got a bunch of small packets (presents or something 
similiar). You want to get rid of the lightest one. You cannot see 
weights, so, what you're doing is basically measuring the weight of 
*every single packet*, compare and pick. No way around.

There might be some ways not having to touch *each* object, if you 
precompute some results. So, in the example above, you could divide the 
packets into two categories, "more than 50 lbs" and "less than 50 lbs", 
for example. I think binary trees might be interesting here but touching 
every object would be way easier.


More information about the Python-list mailing list