campos20

Longest names without repeated letter in WCA.

Jun 25th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. # this program and the extract of the wca export must be in the same folder
  2. # to run, just type "python program.py"
  3.  
  4. # longest name without repeated letters
  5.  
  6. import csv
  7.  
  8. name_list = []
  9. size_list = []
  10. n = 100 # number of people to show
  11. flag = False
  12.  
  13. with open('WCA_export_Persons.tsv','rb') as tsvin:
  14.     tsvin = csv.reader(tsvin, delimiter='\t')
  15.            
  16.     for line in tsvin:
  17.         name = line[2]
  18.         latin = "" # latin letters only
  19.         for x in name:
  20.             if "a"<=x.lower()<="z":
  21.                 latin += x
  22.         if len(latin.lower()) == len(set(latin.lower())):
  23.             name_list += [name]
  24.             size_list += [len(latin)]
  25.    
  26.     count = 0
  27.     position = 1
  28.     previous = 0
  29.     for x, y in sorted(zip(size_list, name_list))[::-1]:
  30.         if count >= n and x != previous:
  31.             break
  32.         print (str(position).zfill(3) if previous != x else "----"), x, y
  33.         count += 1
  34.         previous = x
  35.         position += 1
  36.  
  37. print "\nWCA has", len(name_list), "people with no repeated letter."
Advertisement
Add Comment
Please, Sign In to add comment