I would like to know if theres any possible way to concatenate multiple item in a list and returning another list in a pythonic way.
E.g
[a,b,c,d,e]
If i were to have an output of
[ab,cd,e]
My code would be something like this:
x = ['a','b','c','d','e']
a = []
for i in range(0,len(x),2):
if i + 2 >= len(x):
a.append(x[i])
else:
a.append(x[i] + x[i+1])
Output of a:
['ab','cd','e']
Is there a better way or more pythonic way to do this? I am using python2.7