Answer:
Check the explanation
Explanation:
Executable Code:
def all_permutations(permList, nameList):
# Define the function to create a list
# of all the permutations.
def createPermutationsList(nameList):
# Compute and store the length of the list.
n = len(nameList)
# Return an empty list if the size is 0.
if n == 0:
return []
# Return the element if the size is 1.
if n == 1:
return [nameList]
# Create an empty list to store the permutations.
permList = []
# Start the loop to traverse the list.
for i in range(n):
# Store the first element of the current list.
first = nameList[i]
# Compute the store the remaining list.
remaining = nameList[:i] + nameList[i+1:]
# Start the loop and call the function recursively
# with the remaining list.
for perm in createPermutationsList(remaining):
# Append the element in the permutation list.
permList.append([first] + perm)
# Return the permutation list.
return permList
# Call the function to compute the permutation list
# and store the result.
permList = createPermutationsList(nameList)
# Start the loop to display the values.
for perm in permList:
for val in perm:
print(val, end = " ")
print()
# Call the main() function.
if __name__ == "__main__":
# Prompt the user to enter the input.
nameList = input().split(' ')
permList = []
# Call the function to create and output
# the permutations of the list.
all_permutations(permList, nameList)
#endcode