What do you mean by subclass?

On Aug 16, 2010 3:26 PM, "Emile van Sebille" <em...@fenx.com> wrote:

On 8/16/2010 10:44 AM Chorn, Guillaume said...


>
> Hi All,
>
> I know that I can look up the value for a particular key in a
> dictionary, but can...
Yes.  But you'll need to implement it.  There are likely modules out there
that'll do this, but it'd take more time to look up and evaluate than to
simply write and implement exactly what you need.



> I understand that this could be problematic from the standpoint
> of multiple keys having the sa...
So, in untested code you'd have a function something like:

result = []

for ky, val in dict.items():
 if val == targetval:
 result.append(ky)
return result

If you need repeated access such that iterating over a large dict frequently
impacts performance, you could subclass dict and maintain a second index
allowing instant access to the keys associated with a specific value.

HTH,

Emile



_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to