import itertools permutation_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "=="] permutations = list(itertools.permutations(permutation_list)) print(len(permutations)) for p in permutations: # int(p[0]) * int(p[1] + p[2]) try: if eval(''.join(p)): print(''.join(p).split("==")) except: pass # ['12*483', '5796'] # ['138*42', '5796'] # ['159*48', '7632'] # ['1738*4', '6952'] # ['186*39', '7254'] # ['18*297', '5346'] # ['1963*4', '7852'] # ['198*27', '5346'] # ['28*157', '4396'] y = 0 for i in [5796, 7632, 6952, 7254, 7852, 4396, 5346]: y += i print(y)