7/14 Maintaining Order


#1

I don't know what I'm supposed to be doing... Someone plz help!!

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

Your code here!

duck_index = animals.insert(2, "cobra")

print animals # Observe what prints after the insert operation

Error message: Oops, try again. It looks like duck_index has the value None instead of animals.index("duck") .

It says that duck_index = None, but its actually duck_index = animals.index("duck"), which its supposed to be. Plz help!


#2

Remember, you want to .insert() "cobra" in the place where "duck" is in the list.
try like this:

animals.insert(duck_index, "cobra")


#3

thx - but where in the code do I put that?

duck_index = animals.index("duck") # Use index() to find "duck"

Your code here!

duck_index = animals.insert(duck_index, "cobra")
?


#4

take off "duck_index =" and it will work.
you only use that in the beginning, to find "duck" in the "animals.index"


#5

Thanks for the help, @codermeira


#6

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