from itertools import product
for d in product(range(10), repeat=4):
if 7 in d :
print(d)
This is supposed to print all numbers that have number 7, but what if I want the number that contains exactly one 7?
from itertools import product
for d in product(range(10), repeat=4):
if 7 in d :
print(d)
This is supposed to print all numbers that have number 7, but what if I want the number that contains exactly one 7?
Here is one approach:
for each d
count the number of 7s
, and select the ones that contain exactly one. (thanks @MrXcoder for the assist in the comments)
from itertools import product
for d in product(range(10), repeat=4):
if d.count(7) == 1:
print(d)