How to convert a list by mapping an element into multiple elements in python?
<p>For example,
how to convert [1, 5, 7] into [1,2,5,6,7,8] into python?
[x, x+1 for x in [1,5,7]] can't work for sure...</p>

<p>Not sure if this is the best way, but I would do:</p>

<pre><code>l = [1, 5, 7]
print([y for x in l for y in (x, x + 1)])
</code></pre>

<p>Another way using <a href="https://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable" rel="nofollow"><code>itertools.chain.from_iterable</code></a>:</p>

<pre><code>from itertools import chain
l = [1, 5, 7]
print(list(chain.from_iterable((x, x + 1) for x in l)))
</code></pre>

python