Most viewed recipes tagged "index"http://code.activestate.com/recipes/tags/index/views/2012-12-11T16:59:14-08:00ActiveState Code Recipesget 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> Fast Indexing functions (greater than, less than, equal to, and not equal to) (Python) 2012-03-13T16:21:36-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578071-fast-indexing-functions-greater-than-less-than-equ/ <p style="color: grey"> Python recipe 578071 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/list_comprehension/">list_comprehension</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>). Revision 2. </p> <p>Oftentimes you want to find the index of a list-like object. Numpy arrays, for example, do not have a index member function. These get the job done quickly.</p> <p>Note: these do not raise exceptions, instead they return -1 on error. You should change that if you want different behavior.</p> Create book index. (Python) 2010-04-07T22:20:21-07:00Joseph Reaglehttp://code.activestate.com/recipes/users/4171494/http://code.activestate.com/recipes/577179-create-book-index/ <p style="color: grey"> Python recipe 577179 by <a href="/recipes/users/4171494/">Joseph Reagle</a> (<a href="/recipes/tags/book/">book</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/python/">python</a>). Revision 3. </p> <p>Reads a simple enumeration of "topic (page#|see) subtopic" to create a formatted book index. </p> Poor man's mgrid (Python) 2009-01-21T15:37:13-08:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576625-poor-mans-mgrid/ <p style="color: grey"> Python recipe 576625 by <a href="/recipes/users/4167420/">David Lambert</a> (<a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/index_tricks/">index_tricks</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/mgrid/">mgrid</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/numerical_methods/">numerical_methods</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/scipy/">scipy</a>, <a href="/recipes/tags/trick/">trick</a>). </p> <p>Python 3 code. scipy.mgrid is a useful! This short implementation comes without installing numpy.</p> Coordinates of numpy array from index and shape (Python) 2012-10-23T19:51:55-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578302-coordinates-of-numpy-array-from-index-and-shape/ <p style="color: grey"> Python recipe 578302 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/coordinates/">coordinates</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>returns the coordinates of a numpy array given the index and the shape. A first_index_et function is given as example code</p> An analogue of enumerate for nested lists. (Python) 2012-12-11T16:59:14-08:00John Crichtonhttp://code.activestate.com/recipes/users/4181975/http://code.activestate.com/recipes/578376-an-analogue-of-enumerate-for-nested-lists/ <p style="color: grey"> Python recipe 578376 by <a href="/recipes/users/4181975/">John Crichton</a> (<a href="/recipes/tags/enumerate/">enumerate</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/list/">list</a>). Revision 6. </p> <p>A generator function which enables traversal and modification of deeply nested lists. Together with the supplied helper functions it could be useful when working with data stored in deeply nested lists, particularly when the level of nesting precludes a recursive approach.</p>