Popular recipes by Peter Otten http://code.activestate.com/recipes/users/1780486/2006-08-31T05:51:31-07:00ActiveState Code Recipeszip_pad(), a lazy zip() that pads all but the longest iterable with None (Python)
2006-08-31T05:51:31-07:00Peter Ottenhttp://code.activestate.com/recipes/users/1780486/http://code.activestate.com/recipes/497007-zip_pad-a-lazy-zip-that-pads-all-but-the-longest-i/
<p style="color: grey">
Python
recipe 497007
by <a href="/recipes/users/1780486/">Peter Otten</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>On the rare occasion that you want to fill the sequences passed to zip() with a padding value, at least use something fast.
You can optionally specify a padding value other than None.</p>
zip_exc(), a lazy zip() that ensures that all iterables have the same length (Python)
2006-08-31T03:12:12-07:00Peter Ottenhttp://code.activestate.com/recipes/users/1780486/http://code.activestate.com/recipes/497006-zip_exc-a-lazy-zip-that-ensures-that-all-iterables/
<p style="color: grey">
Python
recipe 497006
by <a href="/recipes/users/1780486/">Peter Otten</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Using zip(names, values) may inadvertently eat some of your data when there are, e. g., fewer values than names. This is easy to fix with assert len(names) == len(values) if the arguments' length is known, but not if they are arbitrary iterables. With zip_exc() no such glitches go unnoticed as list(zip_exc(names, values)) throws a LengthMismatch exception if the number of names and values differ.</p>
Clean up __init__() methods that contain only attribute assignments. (Python)
2004-04-27T01:19:19-07:00Peter Ottenhttp://code.activestate.com/recipes/users/1780486/http://code.activestate.com/recipes/280381-clean-up-__init__-methods-that-contain-only-attrib/
<p style="color: grey">
Python
recipe 280381
by <a href="/recipes/users/1780486/">Peter Otten</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
</p>
<p>Did you ever have to write an initializer whose body consisted of little more than a suite of self.attr = attr style assignments? Here's a utility function that factors out this task.</p>