Maintaining Order problem


#1

I don't quite understanding what is going on in this exercise

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

Your code here!

animals.index("cobra", 3)

print animals # Observe what prints after the insert operation

I'm getting an error message of Oops, try again. It looks like index() was sent to search for an item that is not on the list.
does anyone know what I'm doing wrong?


#2

Hi @remicahrobertson,

Use the duck_index variable to place "cobra" in the correct position within the animals list, as follows ...

    animals.insert(duck_index, "cobra")

Be aware that it is the third position within the list, which has an index of 2.


#3

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