[Python-3000] Iterators for dict keys, values, and items == annoying :)
barry at python.org
Thu Mar 23 22:04:19 CET 2006
On Thu, 2006-03-23 at 14:52 -0500, Jim Fulton wrote:
> If we are dead set on making these methods return iterators, I'd really like
> to see a way to either get non-iterators by calling a method or see some
> new facilities in the iterators returned. Perhaps these iterators
> could have a method for getting a set of values?
What I've found painful as we converted all of our api's from returning
lists (or tuples) to returning iterators, is that the few places that
did random access into the concrete sequence broke, requiring a wrapping
of list() of some other fix.
What I think would be useful would be to add /optional/ support for
__getitem__() to certain iterators. IOW, iterators could chose to
support random access or not. So, dict().keys could support
__getitem__() because it knows the size of the iterator's underlying
sequence. Generators and other iterators could chose to raise TypeError
if they have an unknown size.
There are probably all sorts of reasons why this won't work, but it
seems like it would be useful.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060323/4235fbbd/attachment.pgp
More information about the Python-3000