Feature Requests item #1281053, was opened at 2005-09-02 18:30 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1281053&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: None Status: Closed Resolution: Invalid Priority: 5 Submitted By: Ecnassianer of the Green Storm (ecnassianer) Assigned to: Nobody/Anonymous (nobody) Summary: non-sequence map() arguments for optimization Initial Comment: 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) ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-09-03 11:36 Message: Logged In: YES user_id=80475 Or just: map(function, myList, repeat(anObject, len(myList))) ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2005-09-03 11:26 Message: Logged In: YES user_id=80475 from itertools import imap, repeat list(imap(function, myList, repeat(anObject))) ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-09-03 01:43 Message: 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. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1281053&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com