Creat Your Own


I am using dictionary this this exercise. It has taken awhile but it works. It is basic as you can see.
The question is if I had 500 items, say, in the dictionary, this will loop 500 times. Could you please let me know how to improve on the code below. Cheers

ddict ={"bottleneck": "cetacea", "Clymene": "stenella", "frontlis":"stenella", "sinus":"phocoena"}

print "A non-knowledge of dolphins .."
#attempt at converting a dictionary to list  

for key in ddict:
    if ddict[key] != "cetacea":
        mylist.append(" : ") 
#line 13 enables correct syntax ie spacing around the puntuation coma
        mylist.append(", ")
        print "Dolphins"
#print " " .join(map(str, mylist))

del mylist[len(mylist) -1] # this isto remove the coma at the end of the iteration

#print " " .join(map(str, mylist))

del mylist[len(mylist)-4]
#print " " .join(map(str, mylist))

mylist.insert(len(mylist)-3," and ") 

# the next line does makes it possible that quotationmarks, " ", are not printed. They are still there!!
print "" .join(map(str, mylist)), "are beautiful creatures"

    A non-knowledge of dolphins ..
Clymene : stenella, frontlis : stenella and sinus : phocoena are beautiful creatures


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