I have a dictionary {x: [a,b,c,d], y: [a,c,g,f,h],...}
. So the key is one variable with the value being a list (of different sizes).
My goal is to match up each list against every list in the dictionary and come back with a count of how many times a certain list has been repeated.
I tried this but does not seem to work:
count_dict = {}
counter = 1
for value in dict.values():
count_dict[dict.key] = counter
counter += 1
You could map the lists to tuples so they can be used as keys and use a Counter
dict to do the counting:
from collections import Counter
count = Counter(map(tuple, d.values()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With