Whats it This Time? 7/14


Again. Code for the file:

animals = ["aardvark",  "badger", "duck", "emu", "fennec fox"]
duck_index = index("duck")

# Don't know what to put here

print animals

But when I press Save and Submit, an error comes from both Codacademy and the console.
Oops, try again. Your code looks a bit off. Double check the examples in the instructions if you need help! Your code threw the following error: name 'index' is not defined

And the console error:

Traceback (most recent call last):
   File "python", line 2, in <module>
NameError: name 'index' is not defined

Fix this. Please.


The way you can use index:

duck_index = (variable).index("___")

Now here:

In the directions, after the first directions:

Then .insert(index, item) the string "cobra" at that index.

It says to insert cobra and the index in animals! So, what do you have to do?

animals.index(duck's index, "cobra")


You mean this is the code?

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck")   # Use index() to find "duck"

Hold on, this is the part I'm mostly confused about now.

.insert(index, item)

I forgot the index for "cobra".


Yes, you got:

correct. :smiley:
NOW let's go to your most confusing part.

It says to add "cobra" to animals. So, you use "item". But if you hadn't defined it, how can you use "item"? You are actually adding "item" into the animals index. This might be confusing, so I will give an example:


Now, let's say you want to add the word "RAPUNZEL" to it. So, this would be your code after it:


This would change the array "blam" to:



Now, this section will be showing you what would happen if we did it the way YOU did:
Now, let's start like usual. Here's the array:


Now, you want to add "RAPUNZEL". So, you know it would be an item of the array. So, you write item when inserting.


This will cause an error.
1) "Item" is not a function.
2) "Item" is not stated as a string


So do you get what the problem is? The problem is that you have put "item" instead of "cobra".
Another is that you put "index" here:

When you wrote duck_index.
So, this is the best code for that:

animals.insert(duck_index, "cobra")

Hope this helped!:smiley: TOOK SO LONG. (Haha!)


duck_index = animals.index("duck")

animals.insert(duck_index, "cobra")

This is correct. The mistake I made is I didn't see this:

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index =

Either delete the one you made, or delete the one at the top of the page, and this code will work fine.