Problems at 7/14, Maintaining Order


#1

https://www.codecademy.com/courses/learn-python/lessons/python-lists-and-dictionaries/exercises/maintaining-order?action=lesson_resume

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

#2

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

#3

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