intersection, union, difference, symmetric difference for dictionaries
Tim Chase
python.list at tim.thechases.com
Tue Feb 25 17:10:34 EST 2014
On 2014-02-25 22:54, Peter Otten wrote:
> Tim Chase wrote:
> > If dicts were to support set ops,
>
> They do in 2.7 and 3.x.
>
> >>> a.viewkeys() - b.viewkeys()
> set(['a'])
> >>> a.viewkeys() & b.viewkeys()
> set(['b'])
> >>> a.viewkeys() ^ b.viewkeys()
> set(['a', 'c'])
> >>> a.viewkeys() | b.viewkeys()
> set(['a', 'c', 'b'])
>
> For 3.x replace viewkeys() with keys().
I missed this getting added in the 2.7 release. Thanks for the
introduction to .viewkeys()/.keys() as they could prove quite handy.
-tkc
More information about the Python-list
mailing list