Latest recipes tagged "itertools" and "iterator" but not "offset" and "python"http://code.activestate.com/recipes/tags/itertools-offset+iterator-python/new/2011-06-23T16:36:38-07:00ActiveState Code Recipeslazy ordered unique elements from an iterator (Python)
2011-06-23T16:36:38-07:00Andrew Dalkehttp://code.activestate.com/recipes/users/912777/http://code.activestate.com/recipes/577768-lazy-ordered-unique-elements-from-an-iterator/
<p style="color: grey">
Python
recipe 577768
by <a href="/recipes/users/912777/">Andrew Dalke</a>
(<a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/itertools/">itertools</a>, <a href="/recipes/tags/unique/">unique</a>).
Revision 2.
</p>
<p>This implements a "unique" filter. Its input is an iterator of hashable items. It returns an iterator containing only the unique items of the input, in input order. That is, list(unique("cabbage")) produces ["c", "a", "b", "g"]. The implementation is lazy. The function supports the "key" parameter, which provides an alternate form of comparison.</p>
<p>(Note: a better version of this is available from the itertools documentation as unique_everseen )</p>