Untitled

mail@pastecode.io avatarunknown
plain_text
4 days ago
919 B
0
Indexable
Never
import string


def readFile():
    gruffalotext = open("gruffalo.txt", "r")
    word=""
    gruffalo=[]



    while True:
        char = gruffalotext.read(1)
        if not char:
            break

        if char in string.ascii_letters:
            word += char

        elif char in string.punctuation:
            if char == "'":
                word += char
            else:
                gruffalo.append(word)
                gruffalo.append(char)
                word = ""
        else:
            gruffalo.append(word)
            gruffalo.append(" ")
            word=""

    gruffalotext.close()
    return(gruffalo)


def addtodictionary(words):
    dictionary={}

    while i <= (len(words)):
        if words[i] not in dictionary:
            dictionary[words[i]]= i

    return dictionary









words= readFile()
print(addtodictionary(words))