split an iteration

Robin Becker robin at SPAMREMOVEjessikat.fsnet.co.uk
Thu Mar 31 17:34:35 EST 2005


Peter Otten wrote:
> Robin Becker wrote:
> 
> 
>>Is there a fast way to get enumerate to operate over a slice of an
>>iterable?
> 
> 
> I think you don't need that here:
> 
> e = enumerate(active_nodes)
> for insert_index, a in e:
>     # ...
> 
> for index, a in e:
>     # ...
> 
> Peter
> 

I tried your solution, but I think we miss the split element

eg for
 >>> e = enumerate([0,1,2,3,4,5])
 >>> for i,a in e:
... 	if a==3: break
...
 >>> for i,a in e:
... 	print i,a
...
4 4
5 5
 >>>

I think the second loop needs to start at 3 ie the split needs to be 
start, limit semantics

It would be nice to be able to fix it with a move back method.
-- 
Robin Becker



More information about the Python-list mailing list