Calculating number of the occurrences of an element in a list