I am trying to create a program which takes all text file in a given path and save all strings in one list:
import os
import collections
vocab = set()
path = 'a\\path\\'
listing = os.listdir(path)
unwanted_chars = ".,-_/()*"
vocab={}
for file in listing:
#print('Current file : ', file)
pos_review = open(path+file, "r", encoding ='utf8')
words = pos_review.read().split()
#print(type(words))
vocab.update(words)
pos_review.close()
print(vocab)
pos_dict = dict.fromkeys(vocab,0)
print(pos_dict)
Input
file1.txt: A quick brown fox.
file2.txt: a quick boy ran.
file3.txt: fox ran away.
Output
A : 2
quick : 2
brown : 1
fox : 2
boy : 1
ran : 2
away : 1
Until now I am able to make a dictionary of those strings. But now not sure how to make key, value pair of strings and their frequency in all text files combined.