G2A Many GEOs
SHARE
TWEET

zad.py

pVinc Apr 3rd, 2020 178 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2.  
  3. if __name__ == "__main__":
  4.     list = []
  5.     with open("zadanie2.csv", 'r', newline='') as f:
  6.         for row in csv.reader(f):
  7.             if row[1] == '':
  8.                 continue
  9.  
  10.             list.append(row)
  11.     list = list[1:]
  12.     list.sort(key=lambda x: int(x[0]))
  13.  
  14.     for i in range(1, len(list)):
  15.         if int(list[i][0]) <= int(list[i-1][0]):
  16.             list[i][0] = str(int(list[i-1][0]) + 1)
  17.  
  18.     for i in range(0, len(list)):
  19.         for j in range(0, len(list[i])):
  20.             list[i][j] = list[i][j].lower()
  21.  
  22.     for i in range(0, len(list)):
  23.         for j in range(1, len(list[i])):
  24.             list[i][j] = list[i][j].split()
  25.  
  26.     for i in range(0, len(list)):
  27.         for j in range(1, len(list[i])):
  28.             for k in range(0, len(list[i][j])):
  29.                 try:
  30.                     if ord(list[i][j][k][0]) + 1 == ord(list[i][j][k][1]) or ord(list[i][j][k][0]) - 1 == ord(list[i][j][k][1]):
  31.                         print(list[i][0], list[i][j][k])
  32.                         del list[i][j][k]
  33.                 except IndexError:
  34.                     continue
  35.  
  36.     for i in range(0, len(list)):
  37.         #csv's
  38.         for j in range(1, len(list[i])):
  39.                 #sentences
  40.                 list[i][j] = ' '.join(list[i][j])
  41.  
  42. with open("zadanie2_output.csv", "w", newline='') as f:
  43.     writ = csv.writer(f)
  44.     writ.writerow(["id", "val"])
  45.     for elem in list:
  46.         writ.writerow(elem)
RAW Paste Data
Ledger Nano X - The secure hardware wallet
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