Re: compare dictionaries

2010-09-07 Thread pdlemper
On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba 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 dict1.keys():

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 22:36, Baba wrote: On 7 sep, 22:37, MRAB wrote: On 07/09/2010 21:06, Paul Rubin wrote: Babawrites: 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 numb

Re: compare dictionaries

2010-09-07 Thread Gary Herron
On 09/07/2010 01:26 PM, Baba wrote: On 7 sep, 22:08, Gary Herron 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, an

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba 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) -- http://

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:37, MRAB wrote: > On 07/09/2010 21:06, Paul Rubin wrote: > > > Baba  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 r

Re: compare dictionaries

2010-09-07 Thread Peter Otten
Baba wrote: > On 7 sep, 22:08, Gary Herron 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 th

Re: compare dictionaries

2010-09-07 Thread Shashwat Anand
On Wed, Sep 8, 2010 at 1:56 AM, Baba wrote: > On 7 sep, 22:08, Gary Herron 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 Fal

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 21:06, Paul Rubin wrote: Baba 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 that the letter can

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:08, Gary Herron 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 > whole word

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 in

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba 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

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]: