compare dictionaries

Baba raoulbia at
Tue Sep 7 21:46:36 CEST 2010

level: beginner

word= 'even'
dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2}

i want to know if word is entirely composed of letters in dict2

my approach:
step 1 : convert word to dictionary(dict1)

for k in dict1.keys():
           if k in dict2:
                if dict1[k] != dict2[k]:
                   return False
               return True
           return False
        return True

by adding a print statement i can see that this simply ends too early
e.g. as soon as the first IF condition is met the loop exits

i think this is easy but google and python doc didn't return any good
hints so i'm trying here.

Thanks Baba

More information about the Python-list mailing list