我必须检查数字1到9是否在列表/集合中
if 1 in factor_numbers and 2 in factor_numbers and 3 in factor_numbers and 4 in factor_numbers and 5 in factor_numbers and 6 in factor_numbers and 7 in factor_numbers and 8 in factor_numbers and 9 in factor_numbers and 0 in factor_numbers:
必须有一种更有效的方法来执行此检查?这些数字不一定彼此相邻
答案 0 :(得分:2)
您可以使用为集合定义的定义方法set.issubset
,例如:
set([1, 2, 3, 4, 5, 6, 7, 8, 9]).issubset(set(factor_numbers))