<div dir="ltr"><div><div><div>I had a dictionary indexed by strings, with the value being an array of one or more items. I wanted to know how many had 1 item, how many had 2, etc.<br><br></div><div>My solution was to use Counter from collections:<br><br></div>>>> from collections import Counter<br>>>> d = { 'A': [1], 'B': [2,3], 'C': [4], 'D': [1,2,3]}<br>>>> lens = [ len(value) for value in d.values() ]<br>>>> print(lens)<br>[1, 1, 2, 3]<br>>>> counts = Counter(lens)<br>>>> print(counts)<br>Counter({1: 2, 2: 1, 3: 1})<br>>>> counts[1]<br>2<br><br></div><div>In my case it was a dictionary of 850 entries, with arrays of varying size. It made understanding the composition of the the dictionary easier.<br><br></div><div>What Python module/class/function has made your life easier?<br><br></div></div></div>