map-function

Python 3 Map function is not Calling up function

Python 3 Map function is not Calling up function Question: Why doesn’t following code print anything: #!/usr/bin/python3 class test: def do_someting(self,value): print(value) return value def fun1(self): map(self.do_someting,range(10)) if __name__==”__main__”: t = test() t.fun1() I’m executing the above code in Python 3. I think i’m missing something very basic but not able to figure it out. …

Total answers: 3

Using map() function with keyword arguments

Using map() function with keyword arguments Question: Here is the loop I am trying to use the map function on: volume_ids = [1,2,3,4,5] ip = ‘172.12.13.122’ for volume_id in volume_ids: my_function(volume_id, ip=ip) Is there a way I can do this? It would be trivial if it weren’t for the ip parameter, but I’m not sure …

Total answers: 5

Mapping over values in a python dictionary

Mapping over values in a python dictionary Question: Given a dictionary { k1: v1, k2: v2 … } I want to get { k1: f(v1), k2: f(v2) … } provided I pass a function f. Is there any such built in function? Or do I have to do dict([(k, f(v)) for (k, v) in my_dictionary.iteritems()]) …

Total answers: 8

Understanding the map function

Understanding the map function Question: map(function, iterable, …) Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed …

Total answers: 6

Function application over numpy's matrix row/column

Function application over numpy's matrix row/column Question: I am using Numpy to store data into matrices. Coming from R background, there has been an extremely simple way to apply a function over row/columns or both of a matrix. Is there something similar for python/numpy combination? It’s not a problem to write my own little implementation …

Total answers: 4

Pass multiple parameters to concurrent.futures.Executor.map?

Pass multiple parameters to concurrent.futures.Executor.map? Question: The concurrent.futures.Executor.map takes a variable number of iterables from which the function given is called. How should I call it if I have a generator that produces tuples that are normally unpacked in place? The following doesn’t work because each of the generated tuples is given as a different …

Total answers: 10

Python: Something like `map` that works on threads

Python: Something like `map` that works on threads Question: I was sure there was something like this in the standard library, but it seems I was wrong. I have a bunch of urls that I want to urlopen in parallel. I want something like the builtin map function, except the work is done in parallel …

Total answers: 5

Getting a map() to return a list in Python 3.x

Getting a map() to return a list in Python 3.x Question: I’m trying to map a list into hex, and then use the list elsewhere. In python 2.6, this was easy: A: Python 2.6: >>> map(chr, [66, 53, 0, 94]) [‘B’, ‘5’, ‘x00’, ‘^’] However, in Python 3.1, the above returns a map object. B: …

Total answers: 11

List comprehension vs map

List comprehension vs map Question: Is there a reason to prefer using map() over list comprehension or vice versa? Is either of them generally more efficient or considered generally more Pythonic than the other? Asked By: TimothyAWiseman || Source Answers: map may be microscopically faster in some cases (when you’re not making a lambda for …

Total answers: 14