Popular recipes tagged "selection"http://code.activestate.com/recipes/tags/selection/2011-06-14T17:46:41-07:00ActiveState Code RecipesPick random elements from a predefined list of choices (Python)
2011-06-14T17:46:41-07:00Patrick Dobbshttp://code.activestate.com/recipes/users/4177984/http://code.activestate.com/recipes/577754-pick-random-elements-from-a-predefined-list-of-cho/
<p style="color: grey">
Python
recipe 577754
by <a href="/recipes/users/4177984/">Patrick Dobbs</a>
(<a href="/recipes/tags/choice/">choice</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/selection/">selection</a>).
</p>
<p>This (quick but strangely satisfying) recipe combines the use of random.choice with functools.partial from the standard library. It is a factory function returning random.choice pre-filled with its sequence of options.</p>
Python Tkinter Canvas Rectangle Selection Box (Python)
2010-10-01T02:17:50-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577409-python-tkinter-canvas-rectangle-selection-box/
<p style="color: grey">
Python
recipe 577409
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/rectangle/">rectangle</a>, <a href="/recipes/tags/selection/">selection</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>A simple, yet effective rectangle selection box. :)</p>
<p>Works with a tkinter canvas! Just add the class and set it up like in the example code. The cross heir was my own touch, the RectTracker only draws a box.</p>
<p>Have fun! And please don't just vote down, post what you don't like if you don't like it.</p>
Select some nth smallest elements, quickselect, inplace (Python)
2010-11-30T07:32:42-08:00Teodor Kichatovhttp://code.activestate.com/recipes/users/4176095/http://code.activestate.com/recipes/577477-select-some-nth-smallest-elements-quickselect-inpl/
<p style="color: grey">
Python
recipe 577477
by <a href="/recipes/users/4176095/">Teodor Kichatov</a>
(<a href="/recipes/tags/quickselect/">quickselect</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/selection/">selection</a>).
</p>
<p>fork of <a href="http://code.activestate.com/recipes/269554-select-the-nth-smallest-element/" rel="nofollow">http://code.activestate.com/recipes/269554-select-the-nth-smallest-element/</a>
O(n) quicksort style algorithm for looking up data based on rank order. Useful for finding medians, percentiles, quartiles, and deciles. Equivalent to [data[n] for n in positions] when the data is already sorted.</p>
Search nth smallest element in really big file (Python)
2010-11-30T17:38:38-08:00Teodor Kichatovhttp://code.activestate.com/recipes/users/4176095/http://code.activestate.com/recipes/577478-search-nth-smallest-element-in-really-big-file/
<p style="color: grey">
Python
recipe 577478
by <a href="/recipes/users/4176095/">Teodor Kichatov</a>
(<a href="/recipes/tags/big/">big</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/kth/">kth</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/selection/">selection</a>, <a href="/recipes/tags/smallest/">smallest</a>).
</p>
<p>Search nth smallest float in really big file (more, more and more bigger than available RAM)
in a single pass through the file</p>
<p>if your file more than 150GB - you should use a more appropriate sampling params to the data
more - you can use tempfile to store data(interval) returned from func fill_interval
data:
file with only one float number per line, good shuffled</p>
Functional selection sort (Python)
2009-09-29T13:34:35-07:00pavelhttp://code.activestate.com/recipes/users/4171837/http://code.activestate.com/recipes/576917-functional-selection-sort/
<p style="color: grey">
Python
recipe 576917
by <a href="/recipes/users/4171837/">pavel</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/lambda/">lambda</a>, <a href="/recipes/tags/reduce/">reduce</a>, <a href="/recipes/tags/selection/">selection</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/sorting/">sorting</a>).
Revision 3.
</p>
<p>This is a variant of selection sort without using for-statements. Do you like it? :-)</p>