List and dictionaries: Maintaining order. Need help ASAP


This is the instruction:
Use the .index(item) function to find the index of “duck”. Assign that result to a variable called duck_index.

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

And this is my code:
animals = [“aardvark”, “badger”, “duck”, “emu”, “fennec fox”]
duck_index = animals.index(“duck”)
duck_index =animals.insert(1, “duck”)
animals.insert(2, “cobra”)

print animals # Observe what prints after the insert operation
but it seems not to be working
and this is the response am getting:

It looks like duck_index has the value None instead of animals.index(“duck”) .


Replace this line with your code.

<do not remove the three backticks above>


you’ve two instructions but you did three.

duck_index =animals.insert(1, “duck”)

why did you write this line of code?Do you know you changed the value of duck_index because of this line of code?

and here

animals.insert(2, “cobra”)

now you know it’s no.2 index so you use 2 here but what if you don’t know what index it is?Could duck_index be useful here?


you should input code like :smile: animals.insert(duck_index, “cobra”)


Good day,
I have been unable to do anything for the past three days now cause am
stuck on the Python lists and dictionaries: This Next is key. The code
editor is coming up, it’s just using code editor and I can’t type in it,
even after refreshing it is this the same issue. Please help!
Kindly find attachments of pictures.


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