Popular recipes by Scott S-Allen http://code.activestate.com/recipes/users/4181178/2012-12-03T22:50:47-08:00ActiveState Code RecipesDynamically create a dictionary of ascending paths (Python) 2012-12-03T22:50:47-08:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578354-dynamically-create-a-dictionary-of-ascending-paths/ <p style="color: grey"> Python recipe 578354 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/bootstrap/">bootstrap</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/flexible/">flexible</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/portable/">portable</a>). </p> <p>Ripped from a more elaborate bootstrap script. A sequential set of parent-directories were required for environment variables and subsequent, portable. auto-discovery. </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> Monday of first week per year (not first Monday) (Python) 2012-10-31T04:37:28-07:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578308-monday-of-first-week-per-year-not-first-monday/ <p style="color: grey"> Python recipe 578308 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/week/">week</a>). Revision 4. </p> <p>13th week of any year is ambiguous without identifying the first week. </p> <p>This recipe calculates Monday of the first week, not the first Monday, and differs from others by not using flow-control statement (if).</p> Cheap-date trick; a different way to parse (Python) 2012-03-06T14:08:10-08:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578064-cheap-date-trick-a-different-way-to-parse/ <p style="color: grey"> Python recipe 578064 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/cheap/">cheap</a>, <a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/grep/">grep</a>, <a href="/recipes/tags/parse/">parse</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/sharp/">sharp</a>). </p> <p>... a light meal with a heavy dose of "tutorial mash" on the side.</p> <p>In the constructive spirit of "more ways to solve a problem"; this is a portion of my lateral, occasionally oblique, solutions. Nothing new in le régime de grande, but hopefully the conceptual essence will amuse.</p> <p>Initially started as a response to <a href="http://code.activestate.com/recipes/577135/">recipe 577135</a> which parses incremental date fragments and preserves micro-seconds where available. That script does more work than this, for sure, but requires special flow-control and iterates a potentially incumbering shopping list (multi-dimensional with some detail).</p> <p>So here's a different box for others to play with. Upside-down in a sense, it doesn't hunt for anything but a numerical "pulse"; sequences of digits punctuated by other 'stuff' we don't much care about.</p> <p>Missing a lot of things, intentionally, this snippet provides several examples demoin' flexibility. Easy to button-up, redecorate and extend later for show, till then the delightful commentary makes it hard enough to see bones already -- all six lines or so!</p> <p><strong>Note:</strong> <em>The core script is repeated for illustrative purposes. The first is step-by-step, the second is lean and condensed for utilitarian purposes. It is the second, shorter, version that I yanked from a file and gussied up.</em></p>