# print the key/value pair of a dictionary sorted on value
def printSortedDictionary( D ):
    DS = sorted(D.items(), key=lambda x:x[1])               
    for k in DS:
        print(k)

# strip word of punctuation and convert to all lower-case
def stripWord( w ):
    w = w.replace( ".", "" )
    w = w.replace( ",", "" )
    w = w.replace( ";", "" )
    w = w.replace( ":", "" )
    w = w.replace( "'", "" )
    w = w.replace( "&", "" )
    w = w.replace( "\n", "" )
    w = w.lower()
    return( w )


# build word histogram 
myfile = open( 'DOI.txt', 'r' )
doi = {}
for line in myfile:
    words = line.split(" ")
    for w in words:
        w = stripWord( w )
        if( len(w) > 0 ):
            if w in doi: 
                doi[w] += 1
            else:
                doi[w] = 1
                
myfile.close()
printSortedDictionary( doi )

