My list:
l = ["volcano", "noway", "lease", "sequence", "erupt"]
Desired output:
'volcanowayleasequencerupt'
I have tried:
using itertools.groupby
but it seems like it doesn't work well when there is 2 repeated letters in row (i.e. leasesequence
-> sese
stays):
>>> from itertools import groupby
>>> "".join([i[0] for i in groupby("".join(l))])
'volcanonowayleasesequencerupt'
As you can see it got rid only for the last 'e'
, and this is not ideal because if a letter has double characters they will be shrunk to 1. i.e 'suddenly'
becomes 'sudenly'
.
I'm looking for the most Pythonic approach for this.
Thank you in advance.
EDIT
My list does not have any duplicated items in it.