list('|'.join(['1','2','3']))
should do the trick in which you work with a list of characters.
A more general solution that works for all objects:
from itertools import izip_longest, chain def intersperse(myiter, value): return list( chain.from_iterable(izip_longest(myiter, [], fillvalue=value)) )[:-1]
I am not aware of the built-in / standard library of this function.
In action:
print intersperse([1,2,3], '|')
outputs:
[1, '|', 2, '|', 3]
source share