Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import codecs
- print("Write count of inputed files\n")
- count_of_files = int(input())
- dictionary = {}
- for i in range(1, count_of_files + 1):
- print("Write path to the " + str(i) + " inputed file\n")
- if i == 1:
- print("Example of path: \"/home/username/folder/example.txt\"\n")
- path = str(input())
- with codecs.open(path, "r", "utf-8") as ifs:
- for line in ifs:
- items = line.split()
- for item in items:
- dictionary[item] = dictionary.get(item, 0) + 1
- print("Size of dictionary: " + str(len(dictionary)) + "\n")
- print("Write path to the folder where need to save a dictionary\n")
- print("Example of path: \"/home/username/folder/\"\n")
- path = str(input())
- with codecs.open(path + "dictionary.txt", "w", "utf-8") as ofs:
- for word, count in dictionary.iteritems():
- ofs.write("%s %s\n" % (word, count))
Advertisement
Add Comment
Please, Sign In to add comment