On Feb 14, 9:11 am, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
> On Feb 13, 5:09 pm, Giovanni Bajo <[EMAIL PROTECTED]> wrote:
>
> > > The itertools.repeat(const).next approach wins on speed and
> > > flexibility.
>
> > But it's the most unreadable too.
>
> Not really. It's unusual but plenty r
On Feb 13, 5:09 pm, Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> > The itertools.repeat(const).next approach wins on speed and
> > flexibility.
>
> But it's the most unreadable too.
Not really. It's unusual but plenty readable (no surprise that
repeat(0) repeatedly gives you zero). I think it more
On 13/02/2007 20.01, Raymond Hettinger wrote:
> FWIW, here are three ways of writing constant functions for
> collections.defaultdict():
>
> d = defaultdict(int) # slowest way; works only for zero
> d = defaultdict(lambda: 0) # faster way; works for any constant
> d = defaultdict(it
FWIW, here are three ways of writing constant functions for
collections.defaultdict():
d = defaultdict(int) # slowest way; works only for zero
d = defaultdict(lambda: 0) # faster way; works for any constant
d = defaultdict(itertools.repeat(0).next)# fastest way; works
for any con