I need to be able to write a program that takes a file then returns an array of tokens and then Loop through the array, printing each token one per line, then removes all the punctuation and lower cases each word, then counts how many times the words asked for occur throughout the file. The problem is im having trouble returning the array, I'm not quite sure how to make array that allows the user to type in any word or as many words as he want and then have the program search through the file to find those words.....ive spent 8 hrs and this is all i currently have:
import sys
from scanner import *
def main():
tokens = readTokens("shakespeare.txt")
for i in range(0,len(tokens),1):
print(tokens[i])
def readTokens(fileName):
with open("shakespeare.txt", 'r') as f:
return f.read().split()
token = s.readtoken()
while (token != ""):
print(token)
token = s.readtoken()
s.close()
main()