← 返回题库
中级

itertools排列组合

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    import itertools
    data = [____, ____, ____, ____]
    print(____)
    for combo in itertools.combinations(____):
        print(____)
    print(____)
    for perm in itertools.permutations(____):
        print(____)

示例

输入
solve()
期望输出
3元素组合:
(1, 2, 3)
(1, 2, 4)
(1, 3, 4)
(2, 3, 4)
2元素排列:
(1, 2)
(1, 3)
(1, 4)
(2, 1)
(2, 3)
(2, 4)
(3, 1)
(3, 2)
(3, 4)
(4, 1)
(4, 2)
(4, 3)
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码