Request for useful functions on dicts

Leif leif.poorman at gmail.com
Sun Jul 15 21:47:26 CEST 2012


Thanks for the suggestions, Ian!  I implemented most of them and pushed the code.

> That's because the Pythonic way is to either create a new object and
> return it, or mutate the existing object and return None.

You're saying what I was already thinking.

> In Python 2.7+, intersection and difference could be written using
> dictviews, which act like sets.

I'm debating with myself right now whether to support 2.5 and 2.6.

> def partition(f, d):

Good idea, thanks.

> issubdict could be implemented as a subset operation.  I haven't timed

The current implementation is a bit faster, and it's quite a bit faster on the common (for me) case, where one argument is much smaller than the other.  I wrote it that way because if m=len(first), n=len(second), the amount of work is O(min(m,n)).  Your implementation is O(m + n).  Not really a big deal, unless e.g. m << n. 

--Leif



More information about the Python-list mailing list