Python 3 Map function is not Calling up function

map() returns an iterator, and will not process elements until you ask it to. Turn it into a list to force all elements to be processed: list(map(self.do_someting,range(10))) or use collections.deque() with the length set to 0 to not produce a list if you don’t need the map output: from collections import deque deque(map(self.do_someting, range(10))) but … Read more

Understanding the map function

map isn’t particularly pythonic. I would recommend using list comprehensions instead: map(f, iterable) is basically equivalent to: [f(x) for x in iterable] map on its own can’t do a Cartesian product, because the length of its output list is always the same as its input list. You can trivially do a Cartesian product with a … Read more

Are list-comprehensions and functional functions faster than “for loops”?

The following are rough guidelines and educated guesses based on experience. You should timeit or profile your concrete use case to get hard numbers, and those numbers may occasionally disagree with the below. A list comprehension is usually a tiny bit faster than the precisely equivalent for loop (that actually builds a list), most likely … Read more

Prolog map procedure that applies predicate to list elements

This is usually called maplist/3 and is part of the Prolog prologue. Note the different argument order! :- meta_predicate(maplist(2, ?, ?)). maplist(_C_2, [], []). maplist( C_2, [X|Xs], [Y|Ys]) :- call(C_2, X, Y), maplist( C_2, Xs, Ys). The different argument order permits you to easily nest several maplist-goals. ?- maplist(maplist(test),[[1,2],[3,4]],Rss). Rss = [[1,4],[9,16]]. maplist comes in … Read more