I couldn't find anything just right, so I made it myself. Is it somewhere? What is "just right":
: Basic function of flat. Obvious
flat = lambda xs : (
y
for x in xs
for y in (
[x] if type(x) is not list else
x
)
)
Those who are not on the list are the strategy to lift them up on the list and then disassemble them. I made it a generator according to the style of Python.
With this, flat_map looks like this:
flat_map = lambda f, xs : flat( map( f, xs ) )
If you have any other suggestions, please leave a comment.
Recommended Posts