¡Hi! I was checking out the video walkthrough of this exercise but I read some code that confused me a bit.
These instructions are for spacing the different elements in a string accurately, so that a comma is written in between each of the elements of the list and a dot when the last element of the list has come. The string is the following, where traveler is the name of the traveler and traveler is their destination:
interests_string = "Hi " + traveler + ", we think you'll like these places around " + traveler + ":"
And the part I don’t understand is the following: why does
traveler_attractions[-1] have that “[-1]”? I thought lists elements go from 0 onwards so why use negative numbers?
for i in range(len(traveler_attractions)): if traveler_attractions[-1] == traveler_attractions[i]: interest_string += "the " + traveler attractions[i] + "." else: interest_string += "the " + traveler attractions[i] + ", "
Thanks! (By the way, this code appears in the walkthrough at 1:13:46)