added temp implementation of enumerate

This commit is contained in:
Darren Ranalli 2004-12-01 23:35:31 +00:00
parent c25138f82c
commit 95452c2d5b

View File

@ -20,6 +20,23 @@ from direct.directutil import Verify
# dict.setdefault(key, defaultValue)
# Please use setdefault instead -- Joe
def enumerate(L):
"""Returns (0, L[0]), (1, L[1]), etc., allowing this syntax:
for i, item in enumerate(L):
...
enumerate is a built-in feature in Python 2.3, which implements it
using an iterator. For now, we can use this quick & dirty
implementation that returns a list of tuples that is completely
constructed every time enumerate() is called.
"""
return zip(xrange(len(L)), L)
import __builtin__
if hasattr(__builtin__, 'enumerate'):
print 'enumerate is already present in __builtin__'
else:
__builtin__.enumerate = enumerate
def unique(L1, L2):
"""Return a list containing all items in 'L1' that are not in 'L2'"""