Popular recipes tagged "search"http://code.activestate.com/recipes/tags/search/popular/2017-04-08T12:27:36-07:00ActiveState Code RecipesTkinter search box (Python)
2017-04-08T12:27:36-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580773-tkinter-search-box/
<p style="color: grey">
Python
recipe 580773
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/searchbox/">searchbox</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 9.
</p>
<p>Instead of using two colors for active background and normal background, I use only one color and opacity parameter.</p>
<p>I trigger the feeling of a button using different colors when the mouse is and isn't over. Many modern HTML search boxes uses the same approach.</p>
<p>Command function receives text of entry box when button is pressed.</p>
Recursive find replace in files using regex (Python)
2016-04-28T13:24:15-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/580653-recursive-find-replace-in-files-using-regex/
<p style="color: grey">
Python
recipe 580653
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/search/">search</a>).
Revision 5.
</p>
<h4 id="recursively-find-and-replace-text-in-files-under-a-specific-folder-with-preview-of-changed-data-in-dry-run-mode">Recursively find and replace text in files under a specific folder with preview of changed data in dry-run mode</h4>
<h5 id="example-usage">Example Usage</h5>
<p><strong>See what is going to change (dry run):</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12" --dryrun
</code></pre>
<p><strong>Do actual replacement:</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12"
</code></pre>
<p><strong>Do actual replacement and create backup files:</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12" --create-backup
</code></pre>
<p><strong>Same action as previous command with short-hand syntax:</strong></p>
<pre class="prettyprint"><code>find_replace.py -d project/myfolder -s "\d{4}-\d{2}-\d{2}" -r "2012-12-12" -b
</code></pre>
<p>Output of <code>find_replace.py -h</code>:</p>
<pre class="prettyprint"><code>DESCRIPTION:
Find and replace recursively from the given folder using regular expressions
optional arguments:
-h, --help show this help message and exit
--dir DIR, -d DIR folder to search in; by default current folder
--search-regex SEARCH_REGEX, -s SEARCH_REGEX
search regex
--replace-regex REPLACE_REGEX, -r REPLACE_REGEX
replacement regex
--glob GLOB, -g GLOB glob pattern, i.e. *.html
--dryrun, -dr don't replace anything just show what is going to be
done
--create-backup, -b Create backup files
USAGE:
find_replace.py -d [my_folder] -s <search_regex> -r <replace_regex> -g [glob_pattern]
</code></pre>
asskick.py (Python)
2014-09-20T08:16:57-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578940-asskickpy/
<p style="color: grey">
Python
recipe 578940
by <a href="/recipes/users/4183895/">p@ntut$</a>
(<a href="/recipes/tags/kickass/">kickass</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/torrents/">torrents</a>).
</p>
<p>URL: <a href="http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/" rel="nofollow">http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/</a></p>
<p>Python script to search and download torrents from KickAss torrents.</p>
Setting up a listbox filter in Tkinter(python 2.7) (Python)
2014-04-10T10:25:38-07:00Wyklephhttp://code.activestate.com/recipes/users/4189735/http://code.activestate.com/recipes/578860-setting-up-a-listbox-filter-in-tkinterpython-27/
<p style="color: grey">
Python
recipe 578860
by <a href="/recipes/users/4189735/">Wykleph</a>
(<a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/listbox/">listbox</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/searchbar/">searchbar</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>If you have a listbox and need to filter the contents of the listbox based on the contents of an entry field, this will help you! Shoutout to Nikola-K for the revision. It's much simpler now :D</p>
grep in Python (Python)
2014-03-05T19:47:50-08:00Andy Dustmanhttp://code.activestate.com/recipes/users/2435929/http://code.activestate.com/recipes/578845-grep-in-python/
<p style="color: grey">
Python
recipe 578845
by <a href="/recipes/users/2435929/">Andy Dustman</a>
(<a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/grep/">grep</a>, <a href="/recipes/tags/search/">search</a>).
</p>
<p>The grep() function is inspired by UNIX grep, but is not limited to string patterns and files or streams.</p>
Locate and see the biggest cross in a random matrix (Python)
2013-09-13T13:31:03-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578657-locate-and-see-the-biggest-cross-in-a-random-matri/
<p style="color: grey">
Python
recipe 578657
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>).
</p>
<p>Interesting search space problem.</p>
Search engine (Batch)
2013-10-10T16:18:09-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578646-search-engine/
<p style="color: grey">
Batch
recipe 578646
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/search/">search</a>).
Revision 2.
</p>
<p>Quick search on files index embedded directly in the command script. For example: "search.cmd exe$" - looks for all EXE files in index or just "search.cmd blahblahblah" - looks for all matches with "blahblahblah" in paths. To remove index from script use "search.cmd /fix:me" command (without quotes).</p>
Finding sets in the card game SET! (Python)
2013-04-05T12:49:36-07:00Sander Evershttp://code.activestate.com/recipes/users/4173111/http://code.activestate.com/recipes/578508-finding-sets-in-the-card-game-set/
<p style="color: grey">
Python
recipe 578508
by <a href="/recipes/users/4173111/">Sander Evers</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/setgame/">setgame</a>).
Revision 2.
</p>
<p>In the card game <a href="http://en.wikipedia.org/wiki/Set_%28game%29">SET!</a>, players are shown an array of 12 (or more) symbol cards and try to identify a so-called 3-card <strong>set</strong> among these cards as quickly as possible.</p>
<p>A card has four attributes (number, shape, color and shading), each of which can take 3 possible values. In a <strong>set</strong>, for each attribute, all three cards should have either the same value, or the three different values.</p>
<p>This recipe solves the problem of finding <em>all</em> sets within an array of an arbitrary number of cards, showing some clever optimizations and celebrating the clarity of Python in expressing the algorithms.</p>
Windows Registry: Search & Destroy (Python)
2012-07-12T12:23:05-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578209-windows-registry-search-destroy/
<p style="color: grey">
Python
recipe 578209
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/windows_registry/">windows_registry</a>).
</p>
<p>If you know that your registry has useless information in it and want to remove entries, this recipe was provide you with a simple way of accomplishing such a purpose. After entering strings to match and causing an EOF, the program will search for what you entered, and is designed to automatically delete what was requested. This is committed for archival to be run under Python 2.5 or later versions.</p>
Find Multiple Elements In a List (Python)
2011-11-05T23:40:41-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577943-find-multiple-elements-in-a-list/
<p style="color: grey">
Python
recipe 577943
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/enumerate/">enumerate</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/search_list/">search_list</a>).
</p>
<p>This algorithm searches for more than one element in a list. The input is a list that you want to search through and a list of elements that you want to search for. The output is a multidimensional list with the positions of the elements you are searching for in the search list in the order that you listed them. </p>
Find a line of text in another file (Python)
2012-06-15T15:45:18-07:00sami janhttp://code.activestate.com/recipes/users/4064232/http://code.activestate.com/recipes/578164-find-a-line-of-text-in-another-file/
<p style="color: grey">
Python
recipe 578164
by <a href="/recipes/users/4064232/">sami jan</a>
(<a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/search/">search</a>).
Revision 2.
</p>
<p>This is a simple recipe - it reads a line in file, removes the line-ending and attempts to search throughout another file for the same line, anywhere in the file</p>
<p>In case a line is missing, the line number is printed to stdout</p>
Find Path to Object (Python)
2012-02-05T07:07:33-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578033-find-path-to-object/
<p style="color: grey">
Python
recipe 578033
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/search/">search</a>).
</p>
<p>After wondering what the easiest what to access one object from another was, the following functions were written to automatically discover the shortest path possible. The <code>find</code> function takes the item to find and the object to find it from and tries finding out the best access path. The optional arguments control the search depth, memory usage, et cetera. The <code>nth</code> function is a helper function for accessing data containers that cannot be indexed into. As a final note, line thirteen (<code>while candidates:</code>) will probably never evaluate to false.</p>
Python Multidimensional List Searcher (Python)
2011-10-29T22:21:39-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577929-python-multidimensional-list-searcher/
<p style="color: grey">
Python
recipe 577929
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/element/">element</a>, <a href="/recipes/tags/elements/">elements</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/finder/">finder</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>).
</p>
<p>This module/function lets you find a 2 dimensional list of indices for elements you are looking for in a super list.
Example:</p>
<p>find([1,1,1,2,1,2,3,3],[1,2,3])</p>
<p>returns: [[0, 1, 2, 4], [3, 5], [6, 7]]</p>
Python Binary Search Tree (Python)
2011-08-08T00:15:09-07:00sivarama sarmahttp://code.activestate.com/recipes/users/4178890/http://code.activestate.com/recipes/577830-python-binary-search-tree/
<p style="color: grey">
Python
recipe 577830
by <a href="/recipes/users/4178890/">sivarama sarma</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/maximum/">maximum</a>, <a href="/recipes/tags/minimum/">minimum</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/sort/">sort</a>).
</p>
<p>A data structure that holds a sorted collection of values, and supports efficient insertion, deletion, sorted iteration, and min/max finding. Values may sorted either based on their natural ordering, or on a key function (specified as an argument to the search tree's constructor). The search tree may contain duplicate values (or multiple values with equal keys) -- the ordering of such values is undefined.</p>
<p>This implementation was made with efficiency in mind. In particular, it is more than twice as fast as the other native-Python implementations I tried (which all use objects to store search tree nodes).</p>
<p>See also: <a href="http://en.wikipedia.org/wiki/Binary_search_tree">http://en.wikipedia.org/wiki/Binary_search_tree</a>, <a href="http://en.wikipedia.org/wiki/A*_search_algorithm">http://en.wikipedia.org/wiki/A*_search_algorithm</a></p>
Python Binary Search Tree (Python)
2011-01-10T02:27:08-08:00Edward Loperhttp://code.activestate.com/recipes/users/2637812/http://code.activestate.com/recipes/577540-python-binary-search-tree/
<p style="color: grey">
Python
recipe 577540
by <a href="/recipes/users/2637812/">Edward Loper</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/maximum/">maximum</a>, <a href="/recipes/tags/minimum/">minimum</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/sort/">sort</a>).
Revision 2.
</p>
<p>A data structure that holds a sorted collection of values, and supports efficient insertion, deletion, sorted iteration, and min/max finding. Values may sorted either based on their natural ordering, or on a key function (specified as an argument to the search tree's constructor). The search tree may contain duplicate values (or multiple values with equal keys) -- the ordering of such values is undefined.</p>
<p>This implementation was made with efficiency in mind. In particular, it is more than twice as fast as the other native-Python implementations I tried (which all use objects to store search tree nodes).</p>
<p>See also: <a href="http://en.wikipedia.org/wiki/Binary_search_tree">http://en.wikipedia.org/wiki/Binary_search_tree</a>, <a href="http://en.wikipedia.org/wiki/A*_search_algorithm">http://en.wikipedia.org/wiki/A*_search_algorithm</a></p>
Simple graph algorithms with a modular design (Python)
2011-04-21T13:40:32-07:00jimmy2timeshttp://code.activestate.com/recipes/users/4177690/http://code.activestate.com/recipes/577668-simple-graph-algorithms-with-a-modular-design/
<p style="color: grey">
Python
recipe 577668
by <a href="/recipes/users/4177690/">jimmy2times</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/breadth/">breadth</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/directed/">directed</a>, <a href="/recipes/tags/first/">first</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/oriented/">oriented</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/theory/">theory</a>, <a href="/recipes/tags/undirected/">undirected</a>, <a href="/recipes/tags/visit/">visit</a>).
Revision 7.
</p>
<p>The purpose of this recipe is to look at algorithmic graph theory from an object-oriented perspective.</p>
<p>A graph is built on top of a dictionary indexed by its vertices, each item being the set of neighbours of the key vertex.
This ensures that iterating through the neighbours of a vertex is still efficient in sparse graphs (as with adjacency lists) while at the same time checking for adjacency is expected constant-time (as with the adjacency matrix).</p>
<p>Any valid class of graph must implement the interface defined by AbstractGraph.</p>
<p>A generic search algorithm takes as input a graph, source and target vertices and a queue.
A queue must implement the methods Q.get(), Q.put() and Q.empty() in such a way to get the desired order in visiting the vertices.</p>
<p>Given this pattern, breadth-first and depth-first search are essentially defined by the corresponding expansion policies: the first one uses an actual FIFO queue, the second one a LIFO queue (or stack).</p>
Binary search function. (Python)
2011-02-07T06:37:52-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577565-binary-search-function/
<p style="color: grey">
Python
recipe 577565
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/binary_search/">binary_search</a>, <a href="/recipes/tags/bsearch/">bsearch</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/lower_bound/">lower_bound</a>, <a href="/recipes/tags/optimal_solution/">optimal_solution</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/upper_bound/">upper_bound</a>).
Revision 3.
</p>
<p>For a number of years Python has provided developers with the special parameters 'cmp' and 'key' on list.sort and __builtin__.sorted. However Python does not provide a built-in mechanism for doing binary searches on such sorted lists. This recipe provides a simple function that allows you to perform binary searches on your sorted sequences.</p>
kd-tree for nearest neighbor search in a k-dimensional space (Python)
2010-12-17T15:49:08-08:00Matteo Dell'Amicohttp://code.activestate.com/recipes/users/2433284/http://code.activestate.com/recipes/577497-kd-tree-for-nearest-neighbor-search-in-a-k-dimensi/
<p style="color: grey">
Python
recipe 577497
by <a href="/recipes/users/2433284/">Matteo Dell'Amico</a>
(<a href="/recipes/tags/nearest/">nearest</a>, <a href="/recipes/tags/neighbor/">neighbor</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/tree/">tree</a>).
Revision 5.
</p>
<p>The kd-tree can be used to organize efficient search for nearest neighbors in a k-dimensional space.</p>
Ask a question with Yahoo! Answers and YQL (Python)
2010-11-02T12:55:01-07:00Anand B Pillaihttp://code.activestate.com/recipes/users/4169530/http://code.activestate.com/recipes/577449-ask-a-question-with-yahoo-answers-and-yql/
<p style="color: grey">
Python
recipe 577449
by <a href="/recipes/users/4169530/">Anand B Pillai</a>
(<a href="/recipes/tags/answers/">answers</a>, <a href="/recipes/tags/query/">query</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/yahoo/">yahoo</a>, <a href="/recipes/tags/yql/">yql</a>).
</p>
<p>The web has a lot of resources where on can get answers to questions such as wiki Answers and Yahoo! answers. Of this Y! answers provide a quick and easy way to query it by using Yahoo's own query language, YQL. This recipe demonstrates using Yahoo! answers, YQL and Python to get an answer to your query on the command line.</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>