Re: join dictionaries using keys from one values

2005-12-06 Thread danplawson
Super simple: dict3 = {} for k1 in dict1.keys(): for k2 in dict2.keys(): if dict1.get(k1) == dict2[k2]: dict3[k1] = k2 works in all cases and can be simplified to an iterated dictionary in python 2.4 -- http://mail.python.org/mailman/listinfo/python-list

Re: join dictionaries using keys from one values

2005-12-06 Thread ProvoWallis
Thanks again. This is very helpful. -- http://mail.python.org/mailman/listinfo/python-list

Re: join dictionaries using keys from one values

2005-12-05 Thread Erik Max Francis
ProvoWallis wrote: I'm still learning python so this might be a crazy question but I thought I would ask anyway. Can anyone tell me if it is possible to join two dictionaries together to create a new dictionary using the keys from the old dictionaries? There is no builtin method. The usual

Re: join dictionaries using keys from one values

2005-12-05 Thread bonono
ProvoWallis wrote: I'm still learning python so this might be a crazy question but I thought I would ask anyway. Can anyone tell me if it is possible to join two dictionaries together to create a new dictionary using the keys from the old dictionaries? The keys in the new dictionary would

Re: join dictionaries using keys from one values

2005-12-05 Thread ProvoWallis
Thanks so much. I never would have been able to figure this out on my own. def dictionary_join(one, two): dict2x = dict( ((dict2[k], k) for k in dict2.iterkeys())) dict3 = dict(((k, dict2x[v]) for k,v in dict1.iteritems())) print dict3 dict1 = {1:'bbb', 2:'aaa', 3:'ccc'} dict2 =

Re: join dictionaries using keys from one values

2005-12-05 Thread Devan L
ProvoWallis wrote: Thanks so much. I never would have been able to figure this out on my own. def dictionary_join(one, two): dict2x = dict( ((dict2[k], k) for k in dict2.iterkeys())) dict3 = dict(((k, dict2x[v]) for k,v in dict1.iteritems())) print dict3 dict1 = {1:'bbb',

Re: join dictionaries using keys from one values

2005-12-05 Thread Alex Martelli
ProvoWallis [EMAIL PROTECTED] wrote: ... The keys in the new dictionary would be the keys from the old dictionary one (dict1) and the values in the new dictionary would be the keys from the old dictionary two (dict2). The keys would be joined by matching the values from dict1 and dict2. The