Search code examples
pythonpermutation

ZyBooks name permutation python


I have a problem when learning the zyBooks about Python. 7.4 LAB asks me to write a program about all permutations of names. The details are shown below.

enter image description here

Here is my code but I do not know why there is no output. Could you please help me with it? Really appreciate it.

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)

Solution

  • This worked for me: `

    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))
    

    `