Re: [Tutor] Finding the key for a value in a dictionary.

2007-01-11 Thread Wesley Brooks
Cheers for the reply. I'm creating a custom dictionary that I can use to store list of unique objects used in a GUI. Items are added then a unique string is returned. I have used this approach so if an item is deleted from the storage dictionary I can still find it using the key, where as if I had

Re: [Tutor] Finding the key for a value in a dictionary.

2007-01-11 Thread Kent Johnson
Wesley Brooks wrote: > Dear Users, > > I'm trying to find the key of a unique value within a dictionary. Is > the code bellow a safe way of doing so, or is there a better way of > doing it? > > a = {'de':'df', 'gf':'hg'} > key = a.keys()[a.values().index('hg')] This is safe, as long as the dict

[Tutor] Finding the key for a value in a dictionary.

2007-01-11 Thread Wesley Brooks
Dear Users, I'm trying to find the key of a unique value within a dictionary. Is the code bellow a safe way of doing so, or is there a better way of doing it? a = {'de':'df', 'gf':'hg'} key = a.keys()[a.values().index('hg')] Thanks for your help, Yours Faithfully, Wesley Brooks ___