Problems at 7/14, Maintaining Order


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

I’m starting to get a bit confused with this one, one thread insisted I should merge both animals.insert and animals.index into one, but it has helped little. Could someone help me?

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") and animals.insert(2, "cobra")
print animals


You’ve combined the exercise into a conditional expression with the and.

duck_index should be the index of 'duck' in the animals list.

And then (on a new line) you insert 'cobra' at that index position (meaning use duck_index for the insertion point).

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

# Your code here!
# The insert of 'cobra' goes here

print animals # Observe what prints after the insert operation


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