What am I doing wrong that when printing attractions it’s clear that the function add_attraction isn’t working as intended. I’ve watched the walkthrough provided and my code looks practically the same except I used list comprehension instead of a written out loop statement to create my attractions list.
#Test data test_traveler = ['Erin Wilkes', 'Shanghai, Chaina', ['historical site', 'art']] destinations = ['Paris, France', 'Shanghai, Chaina', 'Los Angeles, USA', 'São Paulo, Brazil', 'Cairo, Egypt'] attractions = [ for destination in destinations] #Work def get_destination_index(destination): destination_index = destinations.index(destination) return destination_index def get_traveler_location(traveler): travel_destination = test_traveler traveler_destination_index = get_destination_index(travel_destination) return traveler_destination_index def add_attraction(destination, attraction): try: destination_index = get_destination_index(destination) attractions_for_destination = attractions[destination_index].append(attraction) except ValueError: return add_attraction('Los Angeles', ['Venice Beach', ['beach']]) print(attractions) #print(attractions) #test_destination_index = get_traveler_location(test_traveler) #print(test_destination_index) #print(get_destination_index('Paris, France'))
Does anyone have an idea? The current terminal output is as follows:
$ python3 script.py [, , , , ]
Also, the first time using the .index() function but seems like that section is working fine.
P.S: I’m following the CS path so I tagged the topic as list-functions/general as the Boredless Tourist project comes after the introduction to list, iteration and loops
Edit1: Added Code
Edit2: Forgot to write what the edit was so edited to explain the edit