[Python-3000] Iterators for dict keys, values, and items == annoying :)

Adam DePrince adam.deprince at gmail.com
Tue Mar 28 18:44:01 CEST 2006


>     for k in d: # or d.keys()
>     for v in d.values():
>     for k, v in d.items():

Right now I'm entertaining two competing "answers" to some of the issues
addressed in this thread.  The first, and easiest to write about and
implement, was to make iters deletable to give the appearance of having
a view in what I thought was the only way we cared.  

The second is views.  My concern was the artificial ordering, and an
explosion of interfaces as we tried to accommodate 2^n feature flats.  I
started a PEP for views as well.  The view PEP will be larger when
finished, I'm proposing a number of interfaces, including proper C-level
interfaces.  

Ironically, when finished, the Set object's methods might be entirely
SetViewInterface methods :-)  

I don't see the mutable iterator going anywhere just yet, for one, as
you mentioned it doesn't work with common use cases, and its proper
operation in the dict is dependent on our specific implementation.  



>  - bounded iterator (supports a length method, guaranteed non-infinite)

Perhaps we can just add to itertools:

def bound( i, c ):
	for x in xrange( c ):
		i.next()

>  - reiterator (supports clone/restart type operations)

itertools.tee or repeat?  


>  - mutable iterator (supports delete and insert, with appropriate guarantees)

The original mutable iterator supported this idea, the sudden explosion
of methods afterward was intended to gauge the communities view of how
rich it should be.  I'll continue this only to see if it grows into
something, but my hopes arn't that hight for it :-) 



> 
> It's only really use cases that can identify which of these might be
> worth supporting.
> 
> Hope this helps,
> Paul.



More information about the Python-3000 mailing list