Pass duck_index as the first argument in insert() (error)


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

print animals.index("duck")

print animals.insert(2,"cobra")

print animals


Are you still having a problem with your code?


Can u help me with it..?


This should be the position of duck in your list not the string,

should be,

duck_index = (2)

so then this line,

can be,

animals.insert(duck_index, "cobra")


Thanks for the help here. I tried a numerical digit in the animals.insert line, I tried "duck", I kept getting errors. Then as soon as I saw this answer I had a "duhhhhh" moment. You are setting "duck_index" to find the position of duck. So the animals.insert(duck_index, "cobra") line, you are just telling it to "check the duck_index line, yo, and replace it with cobra!" The lesson was a bit vague as to WHY we were doing what we were doing.


Thanks for the help bandit :slight_smile:


Correct and correct, haha :smile:


You're welcome @courseplayer78813 :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.