[Python-3000] Iterators for dict keys, values, and items == annoying :)
Nick Coghlan
ncoghlan at gmail.com
Thu Mar 30 23:44:50 CEST 2006
Adam DePrince wrote:
> There seemed to be a concensus in the community on the size of the view
> proposal, and I'm reimplementing the PEP to reflect that. But what I
> can't resolve is the other anciliary issue: "To list or iter." I'm not
> yet ready to resolve that issue. The views don't resolve it either, and
> by their nature are biased towards the iter approach. They provide
> __iter__ because its light weight to do, but there is no way a light
> weight view can provide you with ordering information from an unordered
> datastore. Now, as a means of resolving this conflict, I'm open to the
> notion of a view implementing both __iter__ and an explicit .list method
> to avoid any extra overhead in generating a list from an iter instead of
> directly from the dict as we do now.
Umm, the whole point of the views discussion is the realisation that "list or
iterator" is a false dichotomy. The correct answer is "new iterable that looks
like a container in its own right, but is really just a view of the original".
As far as the value-based comparison goes, yes, in reality the view will need
to have greater knowledge of the underlying container than in my sample
classes in order to be sure of getting a consistent ordering from the
underlying objects.
As Python's own set and dict show, however, unordered collections can be
legitimately compared by value.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list