Maintaining Order


#1

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

animals.insert(2,"cobra")

print animals

what is wrong


#2

@shoknohota,
Have a read through
https://docs.python.org/2/tutorial/datastructures.html

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]

#list.index(x)
#   Return the index in the list of the first item whose value is x. 
#   It is an error if there is no such item.

duck_index = animals.index("duck") 
print duck_index

#list.insert(i, x)
#  Insert an item at a given position. 
#  The first argument is the index of the element before which to insert,
#       so a.insert(0, x) inserts at the front of the list,
#       and a.insert(len(a), x) is equivalent to a.append(x).

animals.insert(2,"cobra")

print animals

#3

I already know that I just don't know how to write the final code and what you say is already in my code "duck" is in the list


#4

I hate these problems that make me think for myself and don't have an example.

Answer (spoiler!)

animals.insert(duck_index, "cobra")


#5

i've allready done it
but thanks any way


#6

this code dont work :frowning:


#11