Re: get keys with the same values

2008-06-17 Thread Wolfgang Grafen
You could use my mseqdict implementation of a sorted dict. http://home.arcor.de/wolfgang.grafen/Python/Modules/Modules.html swap: This method can only be applied when all values of the dictionary are immutable. The Python dictionary cannot hold mutable keys! So swap doesn't work if only one of

Re: get keys with the same values

2008-06-12 Thread Nick Craig-Wood
Paul McGuire <[EMAIL PROTECTED]> wrote: > Instead of all that try/except noise, just use the new defaultdict: > > >>> from collections import defaultdict > >>> > >>> d = {'a' : 1, 'b' : 3, 'c' : 2,'d' : 3,'e' : 1,'f' : 4} > >>> > >>> dd = defaultdict(list) > >>> for key, value in d.items(): > ..

Re: get keys with the same values

2008-06-12 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Jun 12, 6:41 am, David C. Ullrich <[EMAIL PROTECTED]> wrote: > > On Thu, 12 Jun 2008 03:58:53 -0700 (PDT), Nader <[EMAIL PROTECTED]> > > wrote: > > > > >Hello, > > > > >I have a dictionary and will get all keys which ha

Re: get keys with the same values

2008-06-12 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Nader <[EMAIL PROTECTED]> wrote: > On Jun 12, 1:41 pm, David C. Ullrich <[EMAIL PROTECTED]> wrote: > > On Thu, 12 Jun 2008 03:58:53 -0700 (PDT), Nader <[EMAIL PROTECTED]> > > wrote: > > > > >Hello, > > > > >I have a dictionary and will get all keys which have the

Re: get keys with the same values

2008-06-12 Thread Paul McGuire
On Jun 12, 6:41 am, David C. Ullrich <[EMAIL PROTECTED]> wrote: > On Thu, 12 Jun 2008 03:58:53 -0700 (PDT), Nader <[EMAIL PROTECTED]> > wrote: > > >Hello, > > >I have a dictionary and will get all keys which have the same values. > > > d = {'a' : 1, 'b' : 3, 'c' : 2,'d' : 3,'e' : 1,'f' : 4} > > dd

Re: get keys with the same values

2008-06-12 Thread Chris
On Jun 12, 2:15 pm, Nader <[EMAIL PROTECTED]> wrote: > On Jun 12, 2:05 pm, Chris <[EMAIL PROTECTED]> wrote: > > > > > On Jun 12, 1:48 pm, Nader <[EMAIL PROTECTED]> wrote: > > > > On Jun 12, 1:35 pm, [EMAIL PROTECTED] wrote: > > > > > Nader: > > > > > > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3)

Re: get keys with the same values

2008-06-12 Thread Duncan Booth
Nader <[EMAIL PROTECTED]> wrote: > I have a dictionary and will get all keys which have the same values. > > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} > > I will something as : > > d.keys(where their values are the same) > > With this statement I can get two lists for

Re: get keys with the same values

2008-06-12 Thread Nader
On Jun 12, 2:05 pm, Chris <[EMAIL PROTECTED]> wrote: > On Jun 12, 1:48 pm, Nader <[EMAIL PROTECTED]> wrote: > > > > > On Jun 12, 1:35 pm, [EMAIL PROTECTED] wrote: > > > > Nader: > > > > > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} > > > > I will something as : > > > > d.key

Re: get keys with the same values

2008-06-12 Thread Chris
On Jun 12, 1:48 pm, Nader <[EMAIL PROTECTED]> wrote: > On Jun 12, 1:35 pm, [EMAIL PROTECTED] wrote: > > > > > Nader: > > > > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} > > > I will something as : > > > d.keys(where their values are the same) > > > That's magic. > > > > With

Re: get keys with the same values

2008-06-12 Thread Nader
On Jun 12, 1:41 pm, David C. Ullrich <[EMAIL PROTECTED]> wrote: > On Thu, 12 Jun 2008 03:58:53 -0700 (PDT), Nader <[EMAIL PROTECTED]> > wrote: > > >Hello, > > >I have a dictionary and will get all keys which have the same values. > > >d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' :

Re: get keys with the same values

2008-06-12 Thread Nader
On Jun 12, 1:35 pm, [EMAIL PROTECTED] wrote: > Nader: > > > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} > > I will something as : > > d.keys(where their values are the same) > > That's magic. > > > With this statement I can get two lists for this example: > > l1= ['a','e'] >

Re: get keys with the same values

2008-06-12 Thread David C. Ullrich
On Thu, 12 Jun 2008 03:58:53 -0700 (PDT), Nader <[EMAIL PROTECTED]> wrote: >Hello, > >I have a dictionary and will get all keys which have the same values. > >d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} That's not a dictionary, it's a syntax error. If you actually have a d

Re: get keys with the same values

2008-06-12 Thread bearophileHUGS
Nader: > d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} > I will something as : > d.keys(where their values are the same) That's magic. > With this statement I can get two lists for this example: > l1= ['a','e'] > l2=['b','d'] > Would somebody tell me how I can do it? You c

get keys with the same values

2008-06-12 Thread Nader
Hello, I have a dictionary and will get all keys which have the same values. d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)} I will something as : d.keys(where their values are the same) With this statement I can get two lists for this example: l1= ['a','e'] l2=['b','d'] W