How to merge the elements in a list sequentially in python
<p>I have a list <code>[ 'a' , 'b' , 'c' , 'd']</code>. How do I get the list which joins two letters sequentially i.e the ouptut should be <code>[  'ab', 'bc' , 'cd']</code> in python easily instead of manually looping and joining</p>

<p>Use <code>zip</code> within a list comprehension:</p>

<pre><code>In [13]: ["".join(seq) for seq in zip(lst, lst[1:])]
Out[13]: ['ab', 'bc', 'cd']
</code></pre>

<p>Or since you just want to concatenate two character you can also use <code>add</code> operator, by using <a href="https://docs.python.org/3/library/itertools.html#itertools.starmap" rel="nofollow"><code>itertools.starmap</code></a> in order to apply the add function on character pairs:</p>

<pre><code>In [14]: from itertools import starmap

In [15]: list(starmap(add, zip(lst, lst[1:])))
Out[15]: ['ab', 'bc', 'cd']
</code></pre>

python python-2.7