The easiest way to do this is by the programming technique called recursion. If you are not familiar with it, this is a nice opportunity to learn (see for example here). The trick is to start the recursion with the empty list, which we can call route. The recursive function should involve a for loop that goes through the available ports and for each port:

  1. appends it to the list route
  2. removes it from the list of available ports, and
  3. calls the same function with the remaining ports

When the function is called with an empty list of ports, the recursion should stop and print out the list route.

It'll be easiest to work with integer indexes instead of the port names.

So for example, if we start the recursion with route = [0] and ports = [1, 2, 3, 4], meaning that the first stop is always Panama, the first thing to do is to try each of the ports after the 1 in the route to get, for example, route = [0, 3] and continue the recursion with the remaining ports, for example, [1, 2, 4]. To remove item i from the list, you can write ports[:i]+ports[i+1:].