Borderless Tourist: My code is working but I don't know why


#1

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

The part that is confusing me is the add_attractions function

#adds an attraction to the attractions list in the given destination's corresponding index
def add_attraction(destination, attraction):
  try:
    destination_index = get_destination_index(destination)
    attractions_for_destination = attractions[destination_index]
    attractions_for_destination.append(attraction)
    return
  except ValueError:
    return

Specifically, when I run the function and print the list “attractions” (previously defined), the variable “attraction” has been added to the list. But why? As far as I can tell the variable “attraction” is only being appended to attractions_for_destination. Why is it also being added to the list “attractions”?

Also if I re-write the code and just get rid of the variable “attractions_for_destination” and append “attractions” directly I still get the same output. This version of the code makes a lot more sense to me:

#adds an attraction to the attractions list in the given destination's corresponding index
def add_attraction(destination, attraction):
  try:
    destination_index = get_destination_index(destination)
    attractions[destination_index].append(attraction)
    return
  except ValueError:
    return