The Boredless Tourist (add_attraction function)

I have a question of task 31-34.
Why is it instructed or neccessary to define a variable called attractions_for_destination to do the work of appending lists to the attractions variables?

It is supposed to be in this form according to instructions and tutorial.
attractions_for_destination = attractions[destination_index].append(attraction)

Can’t the same results be obtained by just executing the operation of appending, after the previous condition mentioned in the exercise is met, without defining it on a variable? Like in this form:
attractions[destination_index].append(attraction)

I’m just trying to understand if it is an unnecesary variable for this task or there is an important reason for it to be there that I can’t seem to find out. Any response is helpful.

Greetings all!

This is the project’s link:
https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-tourism/modules/cspath-boredless-tourist/projects/the-boredless-tourist

the .append() method doesn’t return anything, so the variable now contains None.

the exercise seems to this in two steps:
first retrieve the attractions on the destination:

attractions_for_destination = attractions[destination_index]

then append:

attractions_for_destination.append(attraction)

Maybe done for readability? Not sure.

2 Likes

Yes I consider its for readability or to look more structured or defined for the class, because the purpose of the function is to modify and add inputs to the attractions list.

I ran the code without defining it as attractions_for_destination, and only doing the append on the attractions list. Only like this:

attractions[destination_index].append(attraction)

It output the same result.

1 Like