Popular Python recipes tagged "compare"http://code.activestate.com/recipes/langs/python/tags/compare/2016-04-14T12:58:40-07:00ActiveState Code RecipesDependency resolution (Python) 2016-04-14T12:58:40-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/580642-dependency-resolution/ <p style="color: grey"> Python recipe 580642 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/dependency/">dependency</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/sorting/">sorting</a>). </p> <p>This recipe shows how to take a list of objects, each with their own list of dependencies, and resolve them to proper order. It includes some poor mans circular dependency detection (very poor mans).</p> List comparison, difference and more using set & frozenset (Python) 2012-11-01T10:30:58-07:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578310-list-comparison-difference-and-more-using-set-froz/ <p style="color: grey"> Python recipe 578310 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/contain/">contain</a>, <a href="/recipes/tags/difference/">difference</a>, <a href="/recipes/tags/lambda/">lambda</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/remove/">remove</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/union/">union</a>). </p> <p>Python has a powerful suite of tools for comparing lists by way of sets and frozensets. Here are a few examples and conveniences that many newcomers, even a few seasoned developers, are unaware.</p> Comparing two images (Python) 2011-04-03T11:13:24-07:00Charlie Clarkhttp://code.activestate.com/recipes/users/4171013/http://code.activestate.com/recipes/577630-comparing-two-images/ <p style="color: grey"> Python recipe 577630 by <a href="/recipes/users/4171013/">Charlie Clark</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/images/">images</a>). </p> <p>Compare two images using the root mean squared analysis. A result close to 0 means a good match.</p> Compare CSV Inventory files (Python) 2009-08-18T14:14:04-07:00Mike Burkehttp://code.activestate.com/recipes/users/4171487/http://code.activestate.com/recipes/576885-compare-csv-inventory-files/ <p style="color: grey"> Python recipe 576885 by <a href="/recipes/users/4171487/">Mike Burke</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/csv/">csv</a>). </p> <p>Program will compare two CSV files using a unique ID field and save any changes to ID as well as two secondary fields (qty &amp; price). The code was written to pick out updates from supplier inventory files.</p> Compare MySQL DB (Python) 2016-02-11T17:31:39-08:00Jice Clavierhttp://code.activestate.com/recipes/users/4089467/http://code.activestate.com/recipes/576589-compare-mysql-db/ <p style="color: grey"> Python recipe 576589 by <a href="/recipes/users/4089467/">Jice Clavier</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/mysql/">mysql</a>). Revision 3. </p> <p>Small module to and check for differences between 2 DB.</p> <p>It will compare the table list, the tables structure and their content.</p> <p>When you run the program, you are ask if you want a detailed comparison. As global comparison will list all the different tables, detailed comparison will output every different record (and will take longer to run)</p> compare(), making filter() fun again (Python) 2008-10-04T12:40:42-07:00Andreas Nilssonhttp://code.activestate.com/recipes/users/4167183/http://code.activestate.com/recipes/576526-compare-making-filter-fun-again/ <p style="color: grey"> Python recipe 576526 by <a href="/recipes/users/4167183/">Andreas Nilsson</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/lambda/">lambda</a>). Revision 2. </p> <p>compare() takes a function parameter and returns a callable comparator when compared to a value. When called, the comparator returns result of comparing the result of calling the function and the value it was created with.</p> <p>Basic usage:</p> <pre class="prettyprint"><code>items = [1, 2, 3, 4, 5] def double(x): return x * 2 for i in filter(compare(double) &gt; 5, items): print i #Prints 3, 4 and 5 </code></pre> get index of element in list using identity (Python) 2008-08-16T19:41:37-07:00nosklohttp://code.activestate.com/recipes/users/4166478/http://code.activestate.com/recipes/576426-get-index-of-element-in-list-using-identity/ <p style="color: grey"> Python recipe 576426 by <a href="/recipes/users/4166478/">nosklo</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/comparision/">comparision</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/identity/">identity</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/is/">is</a>, <a href="/recipes/tags/same_object/">same_object</a>, <a href="/recipes/tags/search/">search</a>). Revision 2. </p> <p>my_list.index(element) returns the index of the element using common comparision (as in == or __eq__() or __cmp__()). If you need to find an element on the list using identity comparing (is) then this function can do it for you</p>