Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. filename = input()
  2.  
  3. f = open(filename, 'r')
  4. data = f.readlines()
  5. f.close()
  6.  
  7. dictionary = {}
  8. list_of_values =[]
  9.  
  10. for i in range(len(data)):
  11.     data[i] = data[i].strip()
  12.  
  13.  
  14. for i in range(0, len(data), 2):
  15.     list_of_values.append(data[i+1])
  16.     if data[i] in dictionary:
  17.         dictionary[data[i]] = "{}; {}".format((dictionary[data[i]]),data[i+1])
  18.     else:
  19.         dictionary[data[i]] = data[i+1]
  20.  
  21.  
  22. f = open('output_keys.txt', 'w')
  23.  
  24. for item in sorted(dictionary.items()):
  25.     f.write(str(item[0])+': '+item[1]+'\n')
  26.  
  27. f.close()
  28.  
  29. f = open('output_titles.txt', 'w')
  30.  
  31. list_of_values.sort()
  32.  
  33. for each in list_of_values:
  34.     f.write(each+'\n')
  35.  
  36. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement