I have a list lst = [1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4,4,4,4,4]
I'm expecting the following output:
out = [1,"","",2,"","","",3,"","","","",4,"","","","","","","",""]
I want to keep the first occurrence of the item and replace all other occurrences of the same item with empty strings.
I tried the following approach.
`def splrep(lst):
from collections import Counter
C = Counter(lst)
flst = [ [k,]*v for k,v in C.items()]
nl = []
for i in flst:
nl1 = []
for j,k in enumerate(i):
nl1.append(j)
nl.append(nl1)
ng = list(zip(flst, nl))
for i,j in ng:
j.pop(0)
for i,j in ng:
for k in j:
i[k] = ''
final = [i for [i,j] in ng]
fin = [i for j in final for i in j]
return fin`
But I'm looking for some simpler or better approaches.