tanchukw

Untitled

Sep 14th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import codecs
  2.  
  3. print("Write count of inputed files\n")
  4. count_of_files = int(input())
  5.  
  6. dictionary = {}
  7. for i in range(1, count_of_files + 1):
  8.     print("Write path to the " + str(i) + " inputed file\n")
  9.     if i == 1:
  10.         print("Example of path: \"/home/username/folder/example.txt\"\n")
  11.     path = str(input())
  12.     with codecs.open(path, "r", "utf-8") as ifs:
  13.         for line in ifs:
  14.             items = line.split()
  15.             for item in items:
  16.                 dictionary[item] = dictionary.get(item, 0) + 1
  17.  
  18. print("Size of dictionary: " + str(len(dictionary)) + "\n")
  19.  
  20. print("Write path to the folder where need to save a dictionary\n")
  21. print("Example of path: \"/home/username/folder/\"\n")
  22. path = str(input())
  23. with codecs.open(path + "dictionary.txt", "w", "utf-8") as ofs:
  24.     for word, count in dictionary.iteritems():
  25.         ofs.write("%s %s\n" % (word, count))
Advertisement
Add Comment
Please, Sign In to add comment