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

"Martin v. Löwis" martin at v.loewis.de
Thu Nov 24 23:32:30 CET 2005

Christoph Zwerschke wrote:
> Sorry. Your answer was good; I missed the point and thought you wrote 
> set(d.keys()). Is it documented anywhere that set(d) = set(d.keys())? I 
> think this should go into the Python Doco where keys() are explained.

It follows from what is documented. set(<iterable object>) creates a
set that contains all elements in the iterable object:


Now, is a dictionary an iterable object? Yes, it is:


Together, this gives the property I demonstrated.

Unfortunately, the PEP apparently hasn't made it into the


More information about the Python-list mailing list