I'm trying to optimize some code thats similiar to this:
anObject = someConstructor() # This isn't a sequence
myList = myListMaker() # This IS a sequence
for items in myList:
function(items, anObject)
I'd like to be able to do this:
map(function, myList, anObject)
But the map function takes two lists, so I have to do
somethign like this:
list2 = []
for x in range(len(myList)):
list2.append(anObject)
map(function, myList, list2)
But intializing list2 kind of defeats the purpose of
optimization. I was looking for some way to convince
anObject that it was really a list containing a lots of
entries of itself, but couldn't find anything in the API.
What I'd love to have is a version of the map function
which takes a function, a sequence, and an object as
arguments and calls the function with the first
argument as an element in the sequence, and the second
element as the object for as many times as their are
items in the sequence.
(Note: Currently the API says if you pass sequences of
unequal lenghths to map, it uses None to fill up the
rest of the calls)
|