Author: Ecnassianer of the Green Storm (ecnassianer)
Date: 2005-09-02 23:30
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)
Logged In: YES user_id=1188172 Use a list comprehension: [function(item, anObject) for item in myList] or, if you must use map, map(lambda item: function(item, anObject), myList) And please direct such questions to comp.lang.python in the future.