pushback iterator

Mike Kazantsev mk.fraggod at gmail.com
Sun May 17 17:22:22 CEST 2009


On Sun, 17 May 2009 16:39:38 +0200
Matus <matusu at gmail.com> wrote:

> I searches web and python documentation for implementation of pushback
> iterator but found none in stdlib.
> 
> problem:
> ========
> when you parse a file, often you have to read a line from parsed file
> before you can decide if you want that line it or not. if not, it would
> be a nice feature to be able po push the line back into the iterator, so
> nest time when you pull from iterator you get this 'unused' line.
>  
...
> 
> proposal:
> =========
> as this is (as I suppose) common problem, would it be possible to extend
> the stdlib of python (ie itertools module) with a similar solution so
> one do not have to reinvent the wheel every time pushback is needed?  

Sounds to me more like an iterator with a cache - you can't really pull
the line from a real iterable like generator function and then just push
it back.
If this "iterator" is really a list then you can use it as such w/o
unnecessary in-out operations.

And if you're "pushing back" the data for later use you might just as
well push it to dict with the right indexing, so the next "pop" won't
have to roam thru all the values again but instantly get the right one
from the cache, or just get on with that iterable until it depletes.

What real-world scenario am I missing here?

-- 
Mike Kazantsev // fraggod.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 205 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20090517/ff214619/attachment.sig>


More information about the Python-list mailing list