在以下代码中;
all_digits = set(range(10))
print all_digits
for i in range(102,167):
digits = set(k for k in (str(i)))
if len(digits) != 3:
continue
print "digits:", digits
remaining_digits = all_digits - digits
print "remaining:", remaining_digits
数字集包含 3 个元素。我想要它们的一组差异,但是,remaining_digits
总是有所有数字。我在这里做错了什么?这是我得到的输出示例;
set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '2'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '3'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '4'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '5'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '6'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '7'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
digits: set(['1', '0', '8'])
remaining: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])