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)
The keys of the dictionary may or may not be implemented with a python object that has a class of "set". 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. For your particular problem, I would use the real set object now that python implements one. But the "python dict keys are a set" concept is an important one nonetheless, as it goes to the understanding of a dictionary data type. One thing about python: its libraries are large and innumerable. Don't expect to know all parts of all of them. You can use it quite readily without knowing every api of every module or every keyword. --Michael -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/ Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com On 9/15/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote: > > Terry Carroll wrote: > > On Fri, 14 Sep 2007, Michael Langford wrote: > > > > > >> What you want is a set, not a list. Lucky for you, a python dict uses > a > >> set for its keys, so cheat and use that. > >> > > > > Is that true? > > > > > >>>> d={1:"a", 2:"b"} > >>>> k=d.keys() > >>>> type(k) > >>>> > > <type 'list'> > > > He worded it incorrectly since there is actually a 'set' type, but what > he meant was that there wouldn't be multiples of each key that you add, > so you would effectively eliminate multiples and thus have a set when > you get a list of dict keys. > -Luke > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor