Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 更改itertools的输出_List_Python 3.x - Fatal编程技术网

List 更改itertools的输出

List 更改itertools的输出,list,python-3.x,List,Python 3.x,输出是 import itertools def x(a,b): x = [[i] for i in itertools.product(a, repeat=b)] return [x] print (x({0,1},3)) 我想要的是它看起来像这样,所有的()都被删除,开始和结束[]都被删除 [[[(0, 0, 0)], [(0, 0, 1)], [(0, 1, 0)], [(0, 1, 1)], [(1, 0, 0)], [(1, 0, 1)], [(1, 1, 0)

输出是

import itertools
def x(a,b):
    x = [[i] for i in itertools.product(a, repeat=b)]
    return [x]
print (x({0,1},3))
我想要的是它看起来像这样,所有的()都被删除,开始和结束[]都被删除

[[[(0, 0, 0)], [(0, 0, 1)], [(0, 1, 0)], [(0, 1, 1)], [(1, 0, 0)], [(1, 0, 1)], [(1, 1,    0)], [(1, 1, 1)]]]
为什么不简单

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]  
或者,如果希望所有元素都是列表

return list(itertools.product(a, repeat=b))

另外,要小心从名为
x
的函数中写入名为
x
的变量;这将给递归带来麻烦。

因为我需要输出[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,0],[1,0,1],[1,1,1,0]]您给出的代码与我想要的代码有相同的问题(0,0,0),第二段代码在python 2.7中工作得非常好,但不是在Python3中,您知道我必须做哪些更改才能在Python3中工作吗
return map(list, itertools.product(a, repeat=b))