views:

124

answers:

2

Do you think that it is OK to use map for an applying function to arguments list and ignore the results?

map(foo, bar)

It may appears as bug to person who is reading code.

+7  A: 

When you want the result using map is a perfectly fine way to apply a function to each item in a list, although many find it clearer to write it as a list comprehension or generator:

result = [foo(x) for x in bar]

However if you don't intend to use the result of the function call and are interested only in the side-effects then you should write using a procedural style instead:

for x in bar:
    foo(x)
Mark Byers
Also, python is highly optimized for this use. List comprehensions are you friend.
Wilduck
+6  A: 

This behavior is frowned upon. Use a for loop unless you intend to make use of the returned list.

Ignacio Vazquez-Abrams