Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from string import ascii_letters
- def read_file(file_path):
- f = open(file_path, 'r')
- return f.read()
- def remove_symbols(InputString):
- return "".join([ch for ch in InputString if ch in (ascii_letters + " ")])
- def print_count_words(string):
- words_in_file = remove_symbols(string)
- words_in_file = words_in_file.split(" ")
- word_count = {}
- for word in words_in_file:
- if word_count.get(word) is not None:
- word_count[word] += 1
- else:
- word_count[word] = 1
- for key in word_count:
- print key + '=' + str(word_count[key])
- def main():
- file = read_file(r'C:\Users\Administrator\Desktop\wordcount_s6SrnKS\alice.txt')
- print print_count_words(file)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement