Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4.  
  5. def get_file(filename):
  6. file = open(filename)
  7. #print(file.readline())
  8.  
  9. dic = {}
  10. d1 = ""
  11. lista = []
  12.  
  13. for line in file:
  14.  
  15. columns = line.split()
  16. if columns[1] == '30':
  17.  
  18. print(columns[2])
  19.  
  20. d = columns[2]
  21. U = columns[3]
  22.  
  23. if d1 == "":
  24. d1 = d
  25. lista.append(U)
  26. elif d1 == d:
  27. lista.append(U)
  28. else:
  29. dic[d1] = lista
  30. del lista[:]
  31. d1 = d
  32. lista.append(U)
  33.  
  34. return(dic)
  35.  
  36. #filename = 'input.txt'
  37. filename = r'E:/Obliczeniowa_bio_kom/zad3/input.txt'
  38. slownik = get_file(filename)
  39.  
  40.  
  41. file2 = open('wynik.txt', 'w')
  42.  
  43. for key in slownik:
  44. for el in slownik[key]:
  45. file2.write(key + ";" + el + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement