Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25371

Re: Request for useful functions on dicts

Newsgroups comp.lang.python
Date 2012-07-15 12:47 -0700
References <38c6d4cb-89b3-4f78-a966-be5ddccec845@googlegroups.com> <mailman.2146.1342373918.4697.python-list@python.org>
Subject Re: Request for useful functions on dicts
From Leif <leif.poorman@gmail.com>
Message-ID <mailman.2151.1342381649.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

> That&#39;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&#39;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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Request for useful functions on dicts Leif <leif.poorman@gmail.com> - 2012-07-14 16:56 -0700
  Re: Request for useful functions on dicts Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-15 11:38 -0600
    Re: Request for useful functions on dicts Leif <leif.poorman@gmail.com> - 2012-07-15 12:47 -0700
    Re: Request for useful functions on dicts Leif <leif.poorman@gmail.com> - 2012-07-15 12:47 -0700

csiph-web