intersection, union, difference, symmetric difference for dictionaries

Tim Chase python.list at tim.thechases.com
Tue Feb 25 23:36:08 CET 2014


On 2014-02-25 22:21, Duncan Booth wrote:
> > It would save some space if I didn't have to duplicate all the
> > keys into sets (on the order of 10-100k small strings), instead
> > being able to directly perform the set-ops on the dicts.  But
> > otherwise, it was pretty readable & straight-forward.
> >     
> It doesn't matter whether they were small strings or full-length
> novels, creating a set from a dict doesn't duplicate any strings.  

pre-my-new-learning-about .viewkeys() it sounds like set(my_dict)
would have the overhead of storing an additional reference to a
string per set-entry (rather than duplicating every string).
With .viewkeys()/.keys(), it sounds like that overhead would go away.

-tkc



More information about the Python-list mailing list