如何获取元组(python)的所有可能组合



我有一点代码,可以使用元组中的坐标在三维空间中绘制立方体。我想通过获取所有可能的点组合并绘制所有三角形来将面添加到立方体中。知道怎么做吗,或者有更好的方法吗。

任何帮助,
谢谢!

#the points I use to make the cube
points = [( 1,  1,  1), ( 1, -1,  1), 
(-1, -1,  1), (-1,  1,  1), 
( 1,  1, -1), ( 1, -1, -1), 
(-1, -1, -1), (-1,  1, -1)]
from itertools import product
def getAllCombos(my_list):
return list(product(*((x, -x) for x in my_list)))

my_list = [1,1,1]
result = getAllCombos(my_list)
print(result)

这将打印:[(1, 1, 1), (1, 1, -1), (1, -1, 1), (1, -1, -1), (-1, 1, 1), (-1, 1, -1), (-1, -1, 1), (-1, -1, -1)]

最新更新