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

Fredrik Lundh fredrik at pythonware.com
Thu Nov 24 03:13:46 EST 2005


bonono at gmail.com wrote:

> Fredrik Lundh wrote:
> > performance is of course another aspect; if you *need* two parallel
> > lists, creating a list full of tuples just to pull them apart and throw
> > them all away isn't exactly the most efficient way to do things.
> >
> > (if performance didn't matter at all, we could get rid most dictionary
> > methods; "iterkeys", "in", and locking should be enough, right?)

> If I need two parallel list(one key, one value), I can still use  the
> same [(k,v)] tuple, just access it as x[0], x[1].

that's a single list containing tuples, not two parallel lists.

this is two parallel lists:

    k = d.keys()
    v = d.values()
    assert isinstance(k, list)
    assert isinstance(v, list)
    use(k, v)

</F>






More information about the Python-list mailing list