Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast!

John Nagle nagle at animats.com
Tue Nov 9 15:39:07 EST 2010


On 11/9/2010 9:32 AM, macm wrote:
> Hi Folks,
>
> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'],
> 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]}
> dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'],
> 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax':
> [[9],34]}
> dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as':
> [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]}
> intersect = filter(dict1.has_key, dict2.keys())
> intersect
> result:
> ['ax', 'ac', 'ab']

     When you've spent a year maintaining and fixing code written
by others, come back and we'll talk.

				John Nagle



More information about the Python-list mailing list