To find the distance between any two occurences
for i in range ( len ( indices [ itr ] ) ) : NEW_LINE INDENT gap = max ( gap , indices [ itr ] [ i ] - start ) NEW_LINE start = indices [ itr ] [ i ] NEW_LINE DEDENT if ( answer [ gap ] == - 1 ) : NEW_LINE INDENT answer [ gap ] = itr NEW_LINE DEDENT