The exercise I’m working on is the Boredless Tourist project. Here’s the relevant code:
attractions = [ for i in range(0, 5)] def add_attraction(destination, attraction): destination_index = get_destination_index(destination) try: attractions_for_destination = attractions[destination_index] attractions_for_destination.append(attraction) return except ValueError: return add_attraction("Los Angeles, USA", ["Venice Beach", ["beach"]]) print(attractions)
The code is working correctly. When I print attractions, it’s been updated with the Venice Beach attraction information.
My problem is that I don’t understand why the “attractions” variable was updated when I appended the attraction data to a whole different variable called attractions_for_destination.
I seem to be missing some important concept about how variables work (namely how and why attractions got updated when I appended data to a different variable. Can someone explain?