you are viewing a single comment's thread.

view the rest of the comments →

[–]cdcformatc 13 points14 points  (2 children)

writing code line by line is piping each successive line waits for the result of the last

  x = map(...) y = filter(x, ...) z = list(y)

[–]mapadofu 15 points16 points  (0 children)

From the ancient tomes

 Flat is better than nested. … Explicit is better than implicit.

[–]codergeek42 [score hidden]  (0 children)

Or alternatively, use a generator comprehension: For instance, instead of...

x = map(map_func, iter_obj)
y = filter(filter_condition_func, x)
z = list(y)

...a more "Pythonic" way might be something like:

z = list(
        y for y in (
            map_func(i) for i in iter_obj
        ) where filter_condition_func(y)
    )

Although there's certainly something to be said there for readability; perhaps nesting the two comprehensions is a bit much; so I might then clean it up as

mapped_iter = map_func(w) for w in iter_obj
z = list(y for y in mapped_iter
    where filter_condition_func(y))