The output is unsorted, and sorting on the second column is not possible. Is there special method to sort on the second value.
This program takes a text and counts how many times a word is in a text
import string
with open("romeo.txt") as file:  # opens the file with text
    lst = []
    d = dict ()
    uniquewords = open('romeo_unique.txt', 'w')
    for line in file:
        words = line.split()
        for word in words:  # loops through all words
            word = word.translate(str.maketrans('', '', string.punctuation)).upper()  #removes the punctuations
            if word not in d:
                d[word] =1
            else:
                d[word] = d[word] +1
            if word not in lst:
                lst.append(word)    # append only this unique word to the list
                uniquewords.write(str(word) + '\n') # write the unique word to the file
print(d)
 
     
    