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 readable (no surprise that > repeat(0) repeatedly gives you zero). I think it more surprising that > int() with no arguments gives you a zero.
Well, if I was doing code review of some of my coworkers I would ask them to use them int if the constant was zero and lambda otherwise. If they wanted to use itertools.repeat(const).next they should prove me that the speed increase is absolutely significant in their actual use case and they should put a big comment in the code explaining why they preferred the cryptic defaultdict(itertools.repeat(0).next) over the obvious defaultdict(int). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list