I know there are many other similar questions posted, but there is a difference in mine that makes it unsolvable with their answers.
I have several lists of characters that may have multiple consecutive spaces, of which I need to keep only one. Repetitions of any other character should remain. I did it in the following way:
myList = ['o', 'e', 'i', ' ', ' ', ' ', 'l', 'k', ' ', ' ', ' ', ' ', ' ', 'j', 'u']
myList_copy = [myList[0]]
for i in range(1, len(myList):
if not(myList[i] == ' ' and myList[i-1] == ' '):
myList_copy.append(myList[i])
which successfully gives me
['o', 'e', 'i', ' ', 'l', 'k', ' ', 'j', 'u', ' ']
I don't really think this is a very good, fast way to do it.
I have seen posts like this one (and others) which have similar questions. However, see that I actually need to remove only repeated spaces. Maybe what I need help with is using groupby to do this, but that's why the new post.
Thanks in advance.