Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Steven D'Aprano
On Tue, 17 Aug 2010 09:12:39 am Huy Ton That wrote: > What do you mean by subclass? It's a fundamental term from object-oriented programming. If you have a class that defines certain data and behaviour, you can create a *subclass* that inherits the same data and behaviour, except for specific e

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Emile van Sebille
On 8/16/2010 4:12 PM Huy Ton That said... What do you mean by subclass? 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.

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Steven D'Aprano
On Tue, 17 Aug 2010 03:44:33 am Chorn, Guillaume wrote: > Hi All, > > I know that I can look up the value for a particular key in a > dictionary, but can I look up the key associated with a particular > value? I understand that this could be problematic from the > standpoint of multiple keys havin

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Chorn, Guillaume
all key-value pairings were unique... -Original Message- From: Dave Angel [mailto:da...@ieee.org] Sent: Monday, August 16, 2010 4:03 PM To: Chorn, Guillaume Cc: tutor@python.org Subject: Re: [Tutor] Question about Dictionaries Chorn, Guillaume wrote: > Hi All, > > I know that I ca

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Alan Gauld
"Chorn, Guillaume" wrote dictionary, but can I look up the key associated with a particular value? Not directly but its not hard to do bearing in mind you will get a collection back.: d = {1:10,2:20,3:10,4:20} val = 10 ks = [k for k in d if d[k] == val] ks [1, 3] You need to trawl

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Huy Ton That
What do you mean by subclass? On Aug 16, 2010 3:26 PM, "Emile van Sebille" 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 modul

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Dave Angel
Chorn, Guillaume wrote: Hi All, I know that I can look up the value for a particular key in a dictionary, but can I look up the key associated with a particular value? I understand that this could be problematic from the standpoint of multiple keys having the same value, but even then I feel li

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Lee Harr
> I know that I can look up the value for a particular key in a > dictionary, but can I look up the key associated with a particular > value? I am using bidict in one of my projects: http://pypi.python.org/pypi/bidict/0.1.1 It's probably a bit more complex than what I need, but the parts I am u

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Emile van Sebille
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 I look up the key associated with a particular value? Yes. But you'll need to implement it. There are likely modules out there that'll do this, but it'd t

[Tutor] Question about Dictionaries

2010-08-16 Thread Chorn, Guillaume
Hi All, I know that I can look up the value for a particular key in a dictionary, but can I look up the key associated with a particular value? I understand that this could be problematic from the standpoint of multiple keys having the same value, but even then I feel like Python could just retur