from collections import Counter low = 152085 high = 670283 print(len(list( \ filter( \ lambda x: len(set(x)) != len(x) \ and list(x) == sorted(x) \ and 2 in set(Counter(x).values())\ , map(str,range(low,high+1)) \ ) \ ) \ ) \ )