flatMap or bind in Python 3?

functional-programming, python

Solution

[y for x in [1, 2, 3] for y in [x, 10*x]]

Just add another `for` to the list comprehension.

Problem

Python provides list comprehensions that provide map/filter type functionality. Can I do a flatMap aka bind operation with this? I've seen solutions with itertools or other add-on libraries. Can I do this with core Python? ``` # this [[x,10*x] for x in [1,2,3]] # will result in unflattened [[1, 10], [2, 20], [3, 30]] ```

Original source

Related problems