I want to write a function that takes a list (in this case, the names of the ports) and prints out all the possible orderings of them. The order in which the permutations are printed doesn't matter, but they should all begin with Panama (PAN).
So far I got to the point to print out all permutations, however, I always fail to print out only those combinations that starts with PAN. Any ideas on how/where to change my code?
import itertools
portnames = ["PAN", "AMS", "CAS", "NYC", "HEL"]
def permutations(route, ports):
# write the recursive function here
# remember to print out the route as the recursion ends
sum = route + ports
perms = list(itertools.permutations(sum))
for perm in perms:
output = []
for item in perm:
output.append(portnames[item])
print(output)
# this will start the recursion with 0 as the first stop
permutations([0], list(range(1, len(portnames))))
"PAN"to the beginning and just add permutations of everything else to that. - ssp