I am encountering difficulties with a program I need to create for my programming class. The class utilizes Python 3, and the assignment is to create a program that reads a file and displays a concordance for said file. The problem I am encountering is that when I run a file through the program, it counts how many of each character are in the program as opposed to words. Here is my program:
print ("enter file name")
f = input()
file = open(f)
z = file.read()
numdict = {}
my_num = 0
with open(f) as file:
[word for line in z for word in line.split()]
for word in z:
if not word in numdict:
numdict[word] = []
numdict[word].append(my_num)
print("word" , "frequency")
for key in sorted(numdict):
print(key, len(numdict[key]))