7/14 maintaining order help


#1

I am having trouble on 7/14 could someone give me an example code? here is what i have
animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") # Use index() to find "duck"

Your code here!

animals.insert(2, "Cobra")

print animals # Observe what prints after the insert operation


#2

put duck_index where you would put 2


#3

I have used the mentioned option, but getting "It looks like "cobra" is not at the correct location (index 4)." - this error.

animals.insert(duck_index,"Cobra")
print animals


#4

Got it, thanks !:relaxed:


#5

i was stuck on the sam cobra is lower case


#6

Hi,

*edit: Ok so in desperation I reset the code, typed it back in identically and now it works immediately, so *puzzled

-> muralighosh, I am having the same problem and you say you solved it but not how :slight_smile:

What did you do? My code is as below:

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

Your code here!

print duck_index
animals.insert(duck_index, "Cobra")

print animals # Observe what prints after the insert operation

but like you I am getting an error message : Oops, try again. It looks like "cobra" is not at the correct location (index 4).

My understanding is: If duck is at index 2 then I am inserting cobra in front of duck therefore cobra is at 2 and duck is now at 3. Where does index 4 come into it?

I can make it work by changing the position of duck in the original list, but surely that isn't the idea?

Could someone put me straight please?

Thanks :slight_smile:


#7

all lower case for "cobra"