map count stores count of s .
count = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT count [ arr [ i ] ] += 1 NEW_LINE DEDENT count_vector = [ ] NEW_LINE for key in count : NEW_LINE INDENT count_vector . append ( [ key , count [ key ] ] ) NEW_LINE DEDENT