Michael Langford wrote: > While the keys() method returns an object of type list, the keys of a > dict (when you leave them in the dict) behave as a "set", as in the > mathematical/computer science idea of a collection of objects where no > two objects have the same value. ( http://en.wikipedia.org/wiki/Set)
Before Python had a real set type, dicts were commonly used as a substitute for a set. > The keys of the dictionary may or may not be implemented with a python > object that has a class of "set". They are not, they are implemented as part of the hashtable that is a dict. In fact set was originally implemented in Python as a wrapper around dict. When it proved to be useful it was re-implemented in C. The original implementation still survives in the set module. The keys() method definitely returns a > list, and I'm sure it does this as that's much more useful than > returning a set object. Actually the designers of Python believe that for the value of dict.keys() to have set-like behaviour is very useful. In Python 3 that is how it will be. http://www.python.org/dev/peps/pep-3106/ _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor