Implements occur-count function for lists