Error in indexing for list


#1

Dear Sir,
Below code is for your coecademy course for maintaining order and this code suppose to find index for "duck" and insert new string "cobra".As per me below code are correct but still it gives me error i.e (Oops, try again. It looks like there may have been a problem with insert() or index(). Double check them!)

CODE:

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

Your code here!

animals.insert(2,"cobra")

print animals # Observe what prints after the insert operation

My regards,
TBIKU


#2

Dear Sir,
I just struck here my lesson is not going for next and all codes seems working fine . Can you check for me please so, that i can go through to next lesson. I am waiting for your usual support..

My regards,
Tbiku


#3

By the way, do you speak Portuguese from Brazil?
It's because I'm seeing the item "naja" in Portuguese!
It is also to facilitate in my reply.


#4

Dear Sir,
I am from Nepal and i have no idea on Portuguese... but this issue block to go through next lesson. So, sir can you please help to get out form this issue.

regards,
TBIKU


#5

OK.
Here's how you should do your code.

animals.index("duck")


animals.insert(duck_index, "item")

#6

Woohhhh, Yes!! i got it thank boss. I just pass the just exact index value instead of putting index value of "duck".
Now i got this whole idea thank you boss. I really appreciate your help.

My regards,
TBIKU


#7

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