Maintaining Order 7/7


#1

Hello everybody,

I´m trying to do this following exercise:

  1. Use the .index(item) function to find the index of "duck". Assign that result to a variable called duck_index.
  2. Then .insert(index, item) the string "cobra" at that index.

So the code I wrote is this:

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

Your code here!

animals.insert(2, "cobra")
print animals # Observe what prints after the insert operation

According to the print duck_index, this one is 2. The instruction is to insert "cobra" at that index, but the console tells "Oops, try again. Make sure to pass duck_index as the first argument in insert()". It is someting wrong in my code? Could you help me please?

Thank you in advance


#2

it seems that when they say "Make sure to pass duck_index as the first argument in insert()", they are being literal, I came here to see an answer, but I used your question to fix us both. Unless someone gives us both a better answer, that's all.
so put duck_index in the insert, instead of 2


#3

Oh, that's rigth, thank you so much for the observation


#4

Thank you so much!!!
It worked perfectly

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

print animals.index("duck")# Your code here!
animals.insert(duck_index, "cobra")

print animals # Observe what prints after the insert operation