Advertisement
campos20

Most common 4 letters in WCA ID

Jul 13th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import csv
  2.  
  3. def common_id():
  4.  
  5.     limit = 100
  6.  
  7.     with open('WCA_export_Persons.tsv','rb') as tsvin:
  8.         tsvin = csv.reader(tsvin, delimiter='\t')
  9.        
  10.         id_list = []
  11.         count = []
  12.        
  13.         for line in tsvin:
  14.             wca_id = line[0][4:8]
  15.            
  16.             if wca_id not in id_list:
  17.                 id_list.append(wca_id)
  18.                 count.append(0)
  19.            
  20.             i = id_list.index(wca_id)
  21.             count[i] += 1
  22.        
  23.         c = 0
  24.         previous = 0
  25.         for x, y in sorted(zip(count, id_list))[::-1]:
  26.             c += 1
  27.             if c>limit and previous != x: break
  28.             print str(x).zfill(3), y
  29.             previous = x
  30.  
  31. common_id()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement