Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast!
Alexander Gattin
xrgtn at yandex.ru
Thu Nov 11 05:04:12 EST 2010
On Thu, Nov 11, 2010 at 11:51:33AM +0200,
Alexander Gattin wrote:
> functional-style code emerges:
>
> > >>> dict(filter(lambda t: t[1],
> > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])),
> > ... filter(dict2.has_key, dict1.iterkeys()))
> > ... )
> > ... )
Sorry, the indentation for the above code
is plain wrong. I'm not accustomed to
lisp-indenting, and only have managed to produce
the next version below:
> >>> dict(filter(lambda t: t[1],
> ... map(lambda k: (k, filter(lambda v: v in dict2[k][0],
> ... dict1[k][0]
> ... )
> ... ),
> ... filter(dict2.has_key, dict1.iterkeys())
> ... )
> ... )
> ... )
> {'ac': [1, 3, '79b'], 'ab': [2, 'd3']}
> >>>
--
With best regards,
xrgtn
More information about the Python-list
mailing list