<p dir="ltr"><br>
On Aug 15, 2015 5:18 PM, "Emile van Sebille" <<a href="mailto:emile@fenx.com">emile@fenx.com</a>> wrote:<br>
><br>
> On 8/15/2015 12:18 PM, Mark Tse wrote:<br>
>><br>
>> Currently, when the function for map() returns a list, the resulting object<br>
>> is an iterable of lists:<br>
>><br>
>>>>> list(map(lambda x: [x, x], [1, 2, 3, 4]))<br>
>><br>
>> [[1, 1], [2, 2], [3, 3], [4, 4]]<br>
>><br>
>> However, a function to convert each element to multiple elements, similar<br>
>> to flatMap (Java) or SelectMany (C#) does not exist, for doing the<br>
>> following:<br>
><br>
><br>
> In addition to the itertools solutions already posted, there's also a flatten function that'll do it:<br>
><br>
> Python 2.7.6 (default, Mar 22 2014, 22:59:56)<br>
> [GCC 4.8.2] on linux2<br>
> Type "help", "copyright", "credits" or "license" for more information.<br>
> >>> from compiler.ast import flatten</p>
<p dir="ltr">Thanks! Hadn't been aware that there is a flatten() func in stdlib.</p>
<p dir="ltr">> >>> flatten ((map(lambda x: [x, x], [1, 2, 3, 4])))<br>
><br>
> [1, 1, 2, 2, 3, 3, 4, 4]<br>
> >>><br>
><br>
> Emile<br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><br>
</p>