Classical FP problem in python : Hamming problem

Steven Bethard steven.bethard at
Thu Jan 27 00:54:09 CET 2005

Francis Girard wrote:
> For the imerge function, what we really need to make the formulation clear is 
> a way to look at the next element of an iteratable without consuming it. Or 
> else, a way to put back "consumed" elements in the front an iteration flow, 
> much like the list constructors in FP languages like Haskell.
> It is simple to encapsulate an iterator inside another iterator class that 
> would do just that. Here's one. The additional "fst" method returns the next 
> element to consume without consuming it and the "isBottom" checks if there is 
> something left to consume from the iteration flow, without actually consuming 
> anything. I named the class "IteratorDeiterator" for lack of imagination :

Another implementation is my peekable class:

It allows you to peek several elements ahead if that's necessary.


More information about the Python-list mailing list