[Python-ideas] Map to Many Function
Alexander Belopolsky
alexander.belopolsky at gmail.com
Sat Aug 15 21:33:48 CEST 2015
On Sat, Aug 15, 2015 at 3:18 PM, Mark Tse <mark.tse at neverendingqs.com> wrote:
> However, a function to convert each element to multiple elements, similar to
> flatMap (Java) or SelectMany (C#) does not exist, for doing the following:
>
>>>> list(mapmany(lambda x: [x, x], [1, 2, 3, 4]))
> [1, 1, 2, 2, 3, 3, 4, 4]
>>> from itertools import chain
>>> list(chain.from_iterable((map(lambda x: [x, x], range(5)))))
[0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
More information about the Python-ideas
mailing list