I need some help. I check, there are few questions about 'counting permutations', but I didn't find an answer suitable for my case.
I would like to count the total number of permutations of each item in a list of items. Say, you have two lists ('first', 'second' see below) and for each element of 'first', I would like to have its total number of unique permutations. e.g for 'a' in 'first' we have
ab ac ad ab ac ad ab ab
by removing duplicates, we have
ab ac ad
So the number of permutations of 'a' will be '3'
The final result I would like to get should be like
(a, 3)
(b, 3)
(c, 3)
(d, 3)
I start with
import itertools
from collections import Counter
first = ['a','b','c','d']
second = [['a','b','c','d'], ['a','b'], ['a','c','d'], ['a','b','d']]
c = Counter()
for let in second:
letPermut = list(set(itertools.permutations(let, 2)))
for i in first:
for permut in letPermut:
if permut[0] == i:
c[i] += 1
for item in c.items():
print(item)
But in the output I get different counts for each element in first
list, and the Counter's results are higher than the expected output. I don't know what I am doing wrong.
Any help?