7. Maintaining Order


#1

Hi, i’m on this topic and i just don’t understand what in the world i’ve done wrong.

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") # Use index() to find "duck"
print duck_index
# Your code here!
animals.insert(2, "cobra")

print animals # Observe what prints after the insert operation

The script shows
2
[‘aardvark’, ‘badger’, ‘cobra’, ‘duck’, ‘emu’, ‘fennec fox’]

But i keep getting a message saying Make sure to pass duck_index as the first argument in insert().
I have no clue what its trying to tell me.
If i could get some help that would be appreciated :slight_smile:


#2

you should use duck_index variable to insert the cobra, not a fixed number. This makes your code more robust and flexible


#3

Wow, thank you for the fast response.
i feel so stupid for not realising earlier now, but thank you :slight_smile:


#4

You’re welcome

Don’t feel stupid about it, you aren’t the first and very likely not the last person to make that mistake


#5

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