Why is dictionary.keys() a list and not a set?

bonono at gmail.com bonono at gmail.com
Thu Nov 24 04:09:08 EST 2005


Fredrik Lundh wrote:
> bonono at gmail.com wrote:
>
> > I know that is a single list of tuples, I mean that can be used as
> > well.
> >
> > for k, _ in d.items(): print k
> > for _, v in d.items(): print v
> > for k in d.keys(): print k
> > for v in d.values(): print v
> >
> > Would there be a noticeable performance difference ?
>
> Sloppy use of print statements is a great way to produce misleading
> benchmarks [1], since the time it takes to print lots of stuff tends to
> overshadow the actual algorithm (for bonus points, print to a terminal
> window, and use "time" to measure performance, so you get startup
> times as well).  If you don't necessarily want to print all the stuff, my
> original assertion still holds:
>
BTW, it is not intended as a speed comparion of but more about the
question of are the for "for"s have speed difference. The print is just
that to complete the statement, I believe it can also be "pass" for
performance purpose.




More information about the Python-list mailing list