Reimplement 'frequencies' using 'collections.defaultdict'