Having trouble on adding a list to a sublist

Link (step 31): https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist

I’m having issues with adding a list to a sublist here. I thought I would use the append option but the hint says otherwise. Here’s the logic I built out so far, but I feel like it’s wrong. Also, is there anyway I can test this to see if it’s correct before I move on?

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "Sao Paulo, Brazil", "Cairo, Egypt"]

test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def get_destination_index(destination):
  destination_index = destinations.index(destination)
  return destination_index

print(get_destination_index("Los Angeles, USA"))

def get_traveler_location(traveler):
  traveler_destination = test_traveler[1]
  traveler_destination_index = get_destination_index           (traveler_destination)
  return traveler_destination_index

test_destination_index = get_traveler_location(test_traveler)


attractions = [[] for x in destinations]


def add_attraction(destination, attraction):
  destination_index = get_destination_index.index(destination)
    destination_index = None
  except ValueError:
  attractions_for_destination = attractions[attraction]
1 Like


In the terminal you can play with this idea:

>>>list = []
>>> list.append([])
>>> list

As for testing it out in your code. You can add a print statement and invoke your function (sometimes it’s useful to use smaller dummy variables for practicality). I usually have a terminal open to the side to load the script and test the variables and functions in the file interactively (helps with debugging).



What terminal do you use on the side to test your code?

If you’re using mac os, it’s the app called “terminal”. If it’s windows you have to install bash (if you haven’t already) and you can run python interactively on it.

1 Like

@toastedpitabread - So I have bash opened in a separate window. How would I test my code that I’ve written in codecademy? Like how would I make a call to it in bash? Would I need to put it in some type of text editor? Thank you so much.

You can open python in it by typing python or python3.
If you want to load a particular file, you should first cd into the directory where that file is location and you can open python there. The you can from myPyFile import * to import all your file assets into the python shell, and interactively play/test your code. Note myPyFile is whatever your file name is called.