Popular recipes by John Reid http://code.activestate.com/recipes/users/4023487/2012-04-30T11:09:05-07:00ActiveState Code RecipesMove files with rename if required (Python) 2012-04-30T11:09:05-07:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/578116-move-files-with-rename-if-required/ <p style="color: grey"> Python recipe 578116 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/move/">move</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 2. </p> <p>A python script that renames (moves) files to a destination directory. However it will not overwrite existing files. The script uses a renaming strategy where a count is incremented in order to avoid naming conflicts.</p> <p>Example usage::</p> <pre class="prettyprint"><code>mv-rename a.ext b.ext target-dir/ </code></pre> <p>would mv a.ext and b.ext into the target directory. If::</p> <pre class="prettyprint"><code>target-dir/a.ext target-dir/b.ext </code></pre> <p>already exist, the newly moved files would be named::</p> <pre class="prettyprint"><code>target-dir/a-&lt;N&gt;.ext target-dir/b-&lt;M&gt;.ext </code></pre> <p>where &lt;N&gt; and &lt;M&gt; are the lowest numbers such that there is no conflict.</p> Red black tree (Python) 2009-06-20T03:11:59-07:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/576817-red-black-tree/ <p style="color: grey"> Python recipe 576817 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/red_black/">red_black</a>, <a href="/recipes/tags/tree/">tree</a>). </p> <p>A straightforward red-black tree implementation based on the algorithms in the "Introduction to Algorithms" book by Cormen, Leiserson, Rivest, Stein. Unfortunately I have not needed delete functionality so this is not implemented yet.</p> Interval (Python) 2009-06-20T02:56:04-07:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/576816-interval/ <p style="color: grey"> Python recipe 576816 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/interval/">interval</a>). </p> <p>A class to represent intervals with some common operations.</p> K fold cross validation partition (Python) 2007-06-16T08:57:51-07:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/521906-k-fold-cross-validation-partition/ <p style="color: grey"> Python recipe 521906 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 3. </p> <p>Takes a sequence and yields K partitions of it into training and validation test sets. Training sets are of size (k-1)*len(X)/K and partition sets are of size len(X)/K</p> Equivalence partition (Python) 2007-01-04T01:45:54-08:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/499354-equivalence-partition/ <p style="color: grey"> Python recipe 499354 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Partitions a set of objects into classes according to some supplied equivalence relation. Useful when you know when objects are equivalent but cannot categorise them into groups easily.</p>