Skip to content

Instantly share code, notes, and snippets.

@Cheaterman
Created April 4, 2024 18:29
Show Gist options
  • Save Cheaterman/0fedbdde96a6fcfb362144f414812870 to your computer and use it in GitHub Desktop.
Save Cheaterman/0fedbdde96a6fcfb362144f414812870 to your computer and use it in GitHub Desktop.
main.py
import collections
import re
text = '''
20. Miguel ReC FIN 30,39 31
21. Mz FIN 30,40 29,5
21. kuiva FIN FIN 30,40 29,5
23. MozMan H K GBR 30,48 27,5
23. oizo! SWE 30,48 27,5
25. Jalli FBE NOR 30,49 25,5
'''
columns = ('id', 'name', 'unknown', 'country', 'number_1', 'number_2')
index_counter = collections.Counter()
for item in text.split('\n'):
for match in re.finditer(r'\S+', item):
index_counter[match.start()] += 1
matching_indices = list(sorted(
index_counter,
key=lambda pos: index_counter[pos],
reverse=True,
))[:len(columns)]
for column, index in zip(columns, sorted(matching_indices)):
print(f'Column {column} is (likely) at index {index} ({index_counter[index]} hits)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment