Wednesday, 4 September 2013

Working with List

# create a list called zoo_animals
zoo_animals=['elephant','snake','lion','baboom','sheep','fox','monkey','zebra','pig','tiger','rabbet','donkey','horse','fish','chinpanzee']
print zoo_animals

# print the seventh index in the list
print zoo_animals[7]

# print the first 10 names in the list
z=zoo_animals[:11]
print z

# change the name of the 10 items in the list
zoo_animals[10]='lizard'
print zoo_animals

# add one more items to the list
zoo_animals.append('alligator')
print zoo_animals

# add one more animals name in the middle
zoo_animals.insert(8,'frog')
print zoo_animals

# count the total #s of items
print len (zoo_animals)

# create a loop that will print all the items in the list

for animal in  zoo_animals:
    print 'feed you %s '%animal
    print zoo_animals

# print the list of the animals in alphabetical
zoo_animals.sort()
print zoo_animals

#create a list of our classmates and print
list_of_classmates=['Rose','Maria','fatu','Linnia','Leone','Victoria','Ma-hawa','Dyna','Jackson']
print list_of_classmates

    

No comments:

Post a Comment