SHARE
TWEET

Untitled

a guest Oct 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         if line.startswith('\n'):
  15.             continue
  16.        
  17.         columns = line.split()
  18.         if columns[1] == '30':
  19.  
  20.             #print(columns[2])
  21.  
  22.             d = columns[2]
  23.             U = columns[3]
  24.  
  25.             if d1 == "":
  26.                 d1 = d
  27.                 lista.append(U)
  28.             elif d1 == d:
  29.                 lista.append(U)
  30.             else:
  31.                 dic[d1] = lista
  32.                 del lista[:]
  33.                 d1 = d
  34.                 lista.append(U)
  35.  
  36.     return(dic)
  37.  
  38. #filename = 'input.txt'
  39. filename = r'E:/Obliczeniowa_bio_kom/zad3/input.txt'
  40. slownik = get_file(filename)
  41.  
  42.  
  43. file2 = open(r'E:/Obliczeniowa_bio_kom/zad3/wynik.txt', 'w')
  44.  
  45. for key in slownik:
  46.     for el in slownik[key]:
  47.         file2.write(key + ";" + el + '\n')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top