У меня есть список:
selection_list=[3, 2, 3, 2, 2, 2]
Я хочу кумулятивно подсчитать количество вхождений каждого элемента, я хочу, чтобы результат был:
['1/2', '1/4' , '2/2', '2/4', '3/4', '4/4'] # 1/2 means: first occurrence of two
dico={'selection':[], 'Number':[]}
l=[]
keys=[]
for i in range(len(selection_list)):
dico['selection'].append(selection_list[i])
#counting the total occurrences of each element
occurrences = collections.Counter(selection_list)
for i in occurrences.keys():
keys.append(i)
#indexes of each element of the list
for j in range(len(keys)):
l.append([i for i,val in enumerate(selection_list) if val==keys[j]])
for i in range(len(l)):
for j in l[i] :
dico['Number'].insert(int(j), str(len(l[i]))+'-'+ str(len(l[i])) )
Я получение этого вывода:
dico={'selection': [2, 3, 2, 3, 3, 3], 'UnfoldingNumber': ['2-2', '4-4', '2-2', '4-4', '4-4', '4-4']}
что мне не хватает?