用例 1:
str = '?0?' #str is input string , we need to replace every '?' with [0,1].
所以结果输出将是:
['000','100','001','101']
用例 2:
str = '?0' #input
预期输出:
['00','10']
用例 3:
str='?'
预期输出:
['0','1']
字符串的长度和 '?' 的个数 in string 可能因不同的输入而异。
这是一个解决方案,用于为 a或数字本身itertools.product
生成所有可能的产品:[0,1]
?
str = '?0?'
[''.join(p) for p in itertools.product(*[['0', '1'] if c == '?' else c for c in str])]
输出:
['000', '001', '100', '101']
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句