相关疑难解决方法(0)

在python中生成两个项目的所有可能长度n组合

我试图从两个可能的项目生成长度n的列表.例如,一个例子可以是,长度为4的列表,包括零,或者是0000,0001,0010,0100,1000,1001等等.先谢谢,杰克

python combinations

1
推荐指数
1
解决办法
771
查看次数

查找列表元素的组合

可能重复:
Python代码从列表中挑选出所有可能的组合?

我有一个清单说[1,2,3].我想找到所有的组合

C(3,1)
[1] [2] [3]

C(3,2)
[1,2] [2,3] [1,3]

C(3,3)
[1,2,3]
Run Code Online (Sandbox Code Playgroud)

这样做有一些模块/库吗?

python

0
推荐指数
1
解决办法
649
查看次数

获取3个列表参数并返回所有组合的函数

我需要帮助在Python中提供一个函数,它接受3个参数列表,并且可以返回所有组合.

例如,如果我跑了:

shirts = ['white', 'blue']
ties = ['purple', 'yellow']
suits = ['grey', 'blue']
combinations = dress_me(shirts, ties, suits)
for combo in combinations:
    print combo
Run Code Online (Sandbox Code Playgroud)

它会打印如下:

('white', 'purple', 'grey')
('white', 'purple', 'blue')
('white', 'yellow', 'grey')
('white', 'yellow', 'blue')
('blue', 'purple', 'grey')
('blue', 'purple', 'blue')
('blue', 'yellow', 'grey')
('blue', 'yellow', 'blue')
Run Code Online (Sandbox Code Playgroud)

python function

-1
推荐指数
1
解决办法
172
查看次数

列出所有组合

我有一个清单[1,2,3].我想要一个接收列表的函数和另一个数字,即长度.

f([1, 2, 3], 4) = [
[1, 1, 1, 1],
[1, 1 , 1, 2],
[1, 1, 1, 3],
[1, 1, 2, 1],
[1, 1, 3, 1],
#and so on...
]
Run Code Online (Sandbox Code Playgroud)

也许itertools有答案?

python python-itertools

-2
推荐指数
1
解决办法
39
查看次数

标签 统计

python ×4

combinations ×1

function ×1

python-itertools ×1