I have a list of strings and numbers l = ['a','a',9,7,'b','c','c','c']
And the output wanted is ['a*2',9,7,'b','c*3']
This is what I have but it can only do '*2' and the last element is not affected by this
a = ['a','a',9,7,'b','c','c','c']
i = 0
while i < len(a)-1:
if a[i] != a[i+1]:
a[i]=str(a[i]).replace(' ','') + '*1 '
i += 1
elif a[i] == a[i+1]:
del a[i+1]
a[i]=str(a[i]).replace(' ','') + '*2 '
i += 1
print(a)
How can I do this ?