Boredless Tourist returns empty list on step 45 despite mirroring the code walkthrough

Hello everyone! I am new to code academy. I’m banging my head against the “Boredless Tourist”

destinations = [“Paris, France”, “Shanghai, China”, “Los Angeles, California”, “São Paulo, Brazil”, “Cairo, Egypt”]
test_traveler = [‘Erin Wilkes’, “Shanghai, China”, [‘historical site’, ‘art’]]
attractions = []
for destination in destinations:

  • attractions.append()*

def get_destination_index(destination):

  • destination_index = destinations.index(destination)*
  • return destination_index*

def get_traveler_location(traveler):

  • traveler_destination = traveler[1]*
  • traveler_destination_index = get_destination_index(traveler_destination)*
  • return traveler_destination_index*

def add_attraction(destination, attraction):

  • destination_index = get_destination_index(destination)*
  • attractions_for_destination = attractions[destination_index].append(attraction)*
  • return attractions_for_destination*

add_attraction(‘Los Angeles, California’, [‘Venice Beach’, [‘beach’]])
add_attraction(“Paris, France”, [“the Louvre”, [“art”, “museum”]])
add_attraction(“Paris, France”, [“Arc de Triomphe”, [“historical site”, “monument”]])
add_attraction(“Shanghai, China”, [“Yu Garden”, [“garden”, “historical site”]])
add_attraction(“Shanghai, China”, [“Yuz Museum”, [“art”, “museum”]])
add_attraction(“Shanghai, China”, [“Oriental Pearl Tower”, [“skyscraper”, “viewing deck”]])
add_attraction(“Los Angeles, California”, [“LACMA”, [“art”, “museum”]])
add_attraction(“São Paulo, Brazil”, [“São Paulo Zoo”, [“zoo”]])
add_attraction(“São Paulo, Brazil”, [“Pátio do Colégio”, [“historical site”]])
add_attraction(“Cairo, Egypt”, [“Pyramids of Giza”, [“monument”, “historical site”]])
add_attraction(“Cairo, Egypt”, [“Egyptian Museum”, [“museum”]])

def find_attractions(destination, interests):

  • destination_index = get_destination_index(destination)*

  • attractions_in_city = attractions[destination_index]*

  • attractions_with_interest = *

  • for attraction in attractions_in_city:*

  •    possible_attraction = attraction*
    
  •    attraction_tags = attractions[1]      *
    
  •    for interest in interests:*
    
  •        if interest in attraction_tags:*
    
  •            attractions_with_interest.append(possible_attraction)*
    
  • print(possible_attraction)*

  • print(attractions_with_interest)*

  • return attractions_with_interest*

la_arts = find_attractions(“Los Angeles, California”, [‘beach’])
print(la_arts)

Output:
“C:\Program Files\Python311\python.exe” “X:\Chris\Projects\Python\The Boredless Tourist\tourist.py”
[‘LACMA’, [‘art’, ‘museum’]]

Whenever it returns the list for “attractions_with_interest” it returns a blank list. I can see through adding print statements to my code that “possible_attractions” has the data I want

However, even after .appending it to attractions_with_interest it shows a blank list. I’ve mirrored the code in the example to the best of my ability. Any thoughts?

I think you have a typo:
You have attraction_tags = attractions[1]

but attractions should be attraction (which is on the previous line)
on the first iteration of the loop, attraction is ['Venice Beach', ['beach']]

your code

formatted code:

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, California", "São Paulo, Brazil", "Cairo, Egypt"]
test_traveler = ['Erin Wilkes', "Shanghai, China", ['historical site', 'art']]
attractions = []
for destination in destinations:
  attractions.append([])

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

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

def add_attraction(destination, attraction):
  destination_index = get_destination_index(destination)
  attractions_for_destination = attractions[destination_index].append(attraction)
  return attractions_for_destination

add_attraction('Los Angeles, California', ['Venice Beach', ['beach']])
add_attraction("Paris, France", ["the Louvre", ["art", "museum"]])
add_attraction("Paris, France", ["Arc de Triomphe", ["historical site", "monument"]])
add_attraction("Shanghai, China", ["Yu Garden", ["garden", "historical site"]])
add_attraction("Shanghai, China", ["Yuz Museum", ["art", "museum"]])
add_attraction("Shanghai, China", ["Oriental Pearl Tower", ["skyscraper", "viewing deck"]])
add_attraction("Los Angeles, California", ["LACMA", ["art", "museum"]])
add_attraction("São Paulo, Brazil", ["São Paulo Zoo", ["zoo"]])
add_attraction("São Paulo, Brazil", ["Pátio do Colégio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])

def find_attractions(destination, interests):
  destination_index = get_destination_index(destination)
  attractions_in_city = attractions[destination_index]
  attractions_with_interest = []
  for attraction in attractions_in_city:
    possible_attraction = attraction
    attraction_tags = attractions[1] ### <- change attractions to attraction
    for interest in interests:
      if interest in attraction_tags:
        attractions_with_interest.append(possible_attraction)
    #print(possible_attraction)
  #print(attractions_with_interest)
  return attractions_with_interest

la_arts = find_attractions("Los Angeles, California", ['beach'])
print(la_arts)

Also, please paste your code on the lines between the ``` and ``` so that its keeps the formatting (like indents)
You can get those using the </> button.

1 Like