Extracting list of keys from 2-key dictionary

mdfranz at my-deja.com mdfranz at my-deja.com
Mon Dec 13 01:06:20 EST 1999


I'm porting a script from perl that uses:

    dict[a,b] instead of $hash{$a}{$b}

My goal is to get a unique list of the second keys for a value, when a=x

In perl, this can be done with:

    @list = keys %{$hash{x}}

Is there a quicker/easier way in python than the snippet below to do
this?

   for a,b in dict.keys():
        if dict.has_key(x,b):
              if b not in list:
                      list.append(b)

TIA,

-matt



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list