loop beats generator expr creating large dict!?

David Isaac aisaac0 at verizon.net
Wed Oct 4 12:30:12 EDT 2006


> Alan Isaac wrote:
> > The current situation is:  use a loop because the obvious generator
> > approach is not efficient.


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message
news:mailman.1165.1159880994.10491.python-list at python.org...
> "not efficient" compared to what ?

I already guess that I've missed your point, but to prove it...
I was referring to the beginning of this thread
where George noted that
palettes = dict((w,set(w)) for w in words)
runs slower than
palettes={}
for w in words:
   palettes[w]=set(w)
The reason seems obvious: the otiose tuple creation,
but there is no "more efficient" syntax to use with 'dict'.

Alan Isaac





More information about the Python-list mailing list