Popular recipes by Michael Chermside http://code.activestate.com/recipes/users/1782375/2005-05-17T15:51:08-07:00ActiveState Code RecipesTesting for an empty iterator (Python)
2005-05-17T15:51:08-07:00Michael Chermsidehttp://code.activestate.com/recipes/users/1782375/http://code.activestate.com/recipes/413614-testing-for-an-empty-iterator/
<p style="color: grey">
Python
recipe 413614
by <a href="/recipes/users/1782375/">Michael Chermside</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 3.
</p>
<p>With lists, it is common to test whether the list is empty and perform special code for the empty case. With iterators, this becomes awkward -- testing whether the iterator is empty will use up the first item! The solution is an idiom based on itertools.tee().</p>
@deprecated (Python)
2005-03-11T14:38:27-08:00Michael Chermsidehttp://code.activestate.com/recipes/users/1782375/http://code.activestate.com/recipes/391367-deprecated/
<p style="color: grey">
Python
recipe 391367
by <a href="/recipes/users/1782375/">Michael Chermside</a>
.
</p>
<p>Java has the "@deprecated" flag (in javadocs) which is used to mark a method as no-longer-current and generates a warning if the method is used. Python can do the same thing.</p>