Append index corresponding to arr [ i ] in the map
for i in range ( len ( arr ) ) : NEW_LINE INDENT if arr [ i ] in M : NEW_LINE INDENT M [ arr [ i ] ] . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT M [ arr [ i ] ] = [ i ] NEW_LINE DEDENT DEDENT