[Python-bugs-list] [ python-Feature Requests-728304 ] reverse form of enumeration

SourceForge.net noreply@sourceforge.net
Sat, 26 Apr 2003 23:30:12 -0700


Feature Requests item #728304, was opened at 2003-04-27 01:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=728304&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Douglas Napoleone (derivin)
Assigned to: Nobody/Anonymous (nobody)
Summary: reverse form of enumeration

Initial Comment:
I love the new enumeration builtin. Before it was put in I 
had my own version of the functionality as many did 
using xrange and zip.

I also used an extension that would give a reverse of 
what enumeration returns (in behavior at least)

enumeration(list)
returns an xrange like itterator that behaves like:
( (0, list[0]), (1, list(1)), ...)

my old code looked like:

def old_enumeration( argList):
_ return zip(range(len(argList)), argList)

def revenum( argList ):
_ temp = old_enumeration( argList)
_ temp.reverse()
_ return temp


obviously this is really slow for really long lists and 
tuples

these structures would be used for looping 90% of the 
time. One of my fav's:
matches = []
for ind, val in revenum(aList):
_ if test(val): matches.append(aList.pop(ind))

am I the only person wanting an effecient reverse 
enumeration??

(NOTE: currently if the list is really long I use:
for ind in xrange(len(aList) - 1, -1, -1):
create two new lists, then delete the old one.
the additional time for pop() is non trivial on a list of 
50Mil entries and memory isnt much of a concern as 
time for me. A reverse enumeration would be much 
clearer to read IMO).



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=728304&group_id=5470