Counting the frequencies in a list using dictionary