compare dictionaries

2010-09-07 Thread Baba
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) step2: for k in dict1.keys(): if k in dict2: if dict1[k] != dict2[k]:

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba raoul...@gmail.com writes: 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 set(word) = set(dict2.keys()) -- http://mail.python.org/mailman/listinfo/python-list

Re: compare dictionaries

2010-09-07 Thread Gary Herron
On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2. Return False if one misses, and True if you get through the whole word: def ...(): for c in word: if c not

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:08, Gary Herron gher...@digipen.edu wrote: On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2.  Return False if one misses, and True if you get through the

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 21:06, Paul Rubin wrote: Babaraoul...@gmail.com writes: 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 set(word)= set(dict2.keys()) Do the numbers in dict2 represent the maximum number of times

Re: compare dictionaries

2010-09-07 Thread Shashwat Anand
On Wed, Sep 8, 2010 at 1:56 AM, Baba raoul...@gmail.com wrote: On 7 sep, 22:08, Gary Herron gher...@digipen.edu wrote: On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in

Re: compare dictionaries

2010-09-07 Thread Peter Otten
Baba wrote: On 7 sep, 22:08, Gary Herron gher...@digipen.edu wrote: On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2. Return False if one misses, and True if you get

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:37, MRAB pyt...@mrabarnett.plus.com wrote: On 07/09/2010 21:06, Paul Rubin wrote: Babaraoul...@gmail.com  writes: 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 set(word)= set(dict2.keys())

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba raoul...@gmail.com writes: for k in word.keys(): if k not in hand: return False elif k in hand: if word[k] hand[k]: return False return True Untested: all(word[k] = hand.get(k,0) for k in word)

Re: compare dictionaries

2010-09-07 Thread Gary Herron
On 09/07/2010 01:26 PM, Baba wrote: On 7 sep, 22:08, Gary Herrongher...@digipen.edu wrote: On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2. Return

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 22:36, Baba wrote: On 7 sep, 22:37, MRABpyt...@mrabarnett.plus.com wrote: On 07/09/2010 21:06, Paul Rubin wrote: Babaraoul...@gmail.comwrites: 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

Re: compare dictionaries

2010-09-07 Thread pdlemper
On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba raoul...@gmail.com wrote: 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) step2: for k in