I have a list in Python:
list
l = [\'a\', \'c\', \'e\', \'b\']
I want to duplicate each element immediately next to the original.>
>>> l = ['a', 'c', 'e', 'b'] >>> [x for pair in zip(l,l) for x in pair] ['a', 'a', 'c', 'c', 'e', 'e', 'b', 'b']
Or
>>> from itertools import repeat >>> [x for item in l for x in repeat(item, 2)] ['a', 'a', 'c', 'c', 'e', 'e', 'b', 'b']