diff --git a/snippets/frequencies.md b/snippets/frequencies.md index 13657b0b9..f78fe75b5 100644 --- a/snippets/frequencies.md +++ b/snippets/frequencies.md @@ -6,14 +6,15 @@ tags: list,intermediate Returns a dictionary with the unique values of a list as keys and their frequencies as the values. - Use `collections.defaultdict()` to store the frequencies of each unique element. -- Use `dict()` constructor to return a dictionary with the unique elements of the list as keys and their frequencies as the values. +- Use `dict()` to return a dictionary with the unique elements of the list as keys and their frequencies as the values. ```py from collections import defaultdict + def frequencies(lst): freq = defaultdict(int) for val in lst: - freq[val]+=1 + freq[val] += 1 return dict(freq) ```