Help finding the index location of a parameter

I am working on #11 in the project here:

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

I’m trying to figure out what argument I should put in my .index() function to find the index location of my pararementer. I’m not sure what I should put here, if it’s a number, variable, parameter, etc? I’m having trouble grasping the concept of this.

Here is my current code:

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "Sao Paulo, Brazil", "Cairo, Egypt"]

test_travelar = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def get_destination_index(destination):
  index_of_dest = destination.index()
  return index_of_dest

get_destination_index("Los Angeles, USA")
print(get_destination_index)

Hi there.

In situations like this, the documentation is your best friend.

You should familiarise yourself with the process of looking things like this up in the official docs. :slight_smile:

1 Like

@thepitycoder

This documentation is awesome. I’ll have to bookmark this page.

However, I’m still having a hard time finding out how to find what place an argument is within a list. Here I am calling my function where I am returning (what I believe to be the correct variables for the index) to my function.

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "Sao Paulo, Brazil", "Cairo, Egypt"]

test_travelar = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def get_destination_index(destination):
  index_of_dest = destinations.index(destination)
  return index_of_dest

get_destination_index("Los Angeles, USA")
print(get_destination_index)

Here, you’ve called the function, but the return value is lost. You havn’t assigned it to a variable, or printed it out.

This line prints something like: <function get_destination_index at 0x7f2b8ba5df28>

If you were to combine those two lines, you’ll see what you’re looking for:

print(get_destination_index("Los Angeles, USA")) #this calls the function, and passes the return value as the argument to the print function

Or, you could assign a variable to the return value of the function call, if you need it for future operations, and pass the variable as the argument to print():

dest_index = get_destination_index("Los Angeles, USA")
print(dest_index)
4 Likes

@midlindner

Thank you, I was mistaken and thought that the call and the print needed to be two separate operations. Looks like my function was actually correct, it was just my call/print were wrong. Thanks so much.

1 Like