from itertools import * a = '0123' ap=[] for i in product(a, repeat=3): if i[0]!='0' and i[0]+i[2]>i[1]: ap.append(i) print(len(ap))