Untitled
unknown
plain_text
2 years ago
919 B
7
Indexable
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))
Editor is loading...