ZyBooks 名称排列 python

问题描述 投票:0回答:1

我在学习 zyBooks 的 Python 时遇到了问题。 7.4 LAB 让我写一个关于所有名字排列的程序。详情如下所示。

这是我的代码,但我不知道为什么没有输出。你能帮我吗?真的很感激。

def all_permutations(permList, nameList):
    # TODO: Implement method to create and output all permutations of the list of names.
    import itertools
    permList = list(itertools.permutations(nameList))
    return permList

if __name__ == "__main__": 
    nameList = input().split(' ')
    permList = []
    all_permutations(permList, nameList)
python permutation
1个回答
0
投票

这对我有用: `

def all_permutations(permList, nameList):
    # TODO: Implement method to create and output all permutations of the list of names.
    import itertools
    permList = list(itertools.permutations(nameList))
    return permList

if __name__ == "__main__": 
    nameList = input().split(' ')
    permList = all_permutations([], nameList)
    for perm in permList:
        print(' '.join(perm))

`

© www.soinside.com 2019 - 2024. All rights reserved.