Skip to content

Instantly share code, notes, and snippets.

@gleb-chipiga
Last active April 30, 2024 16:48
Show Gist options
  • Save gleb-chipiga/943eff23361ce2951431617c697b0988 to your computer and use it in GitHub Desktop.
Save gleb-chipiga/943eff23361ce2951431617c697b0988 to your computer and use it in GitHub Desktop.
Выбры НП 2024
Никита Черняк Дмитрий Серегин Полина Гаврина
1 2 3
2 1 3
3 2 1
2 1 3
2 1 3
1 2 3
1 2 3
1 2 3
3 2 1
3
2 1 3
3 1 2
2 1 3
3 1 2
1 2 3
2 1 3
2 1 3
2 1 3
1 3 2
3
2 1 3
3 2 1
2 1 3
3 1 2
2 1 3
2 1 3
1 3 2
import csv
with open("np_concil.csv") as file:
reader = csv.reader(file)
candidates = next(reader)
results = {c: 0 for c in candidates}
for row in reader:
row_votes = [(i, int(row[i])) for i in range(len(row)) if row[i] != ""]
row_votes = sorted(row_votes, key=lambda t: t[1], reverse=True)
for index, _ in row_votes:
results[candidates[index]] += 1
print(results)
Дмитрий Наумов Мария Чебыкина Глеб Чипига Сергей Ян
1 3 4 2
2 3 1 4
1 4 2 3
3 1 4 2
1 2 3 4
4 2 3
4 2 3 1
2 4 3 1
3 2 4 1
4 2 3 1
1 3 4 2
3 2 4
4
3 4
1 2 4 3
4
1 4 2 3
2 1 3 4
1 3 2 4
1 2 3 4
4 2 3 1
2
1 2 3 4
1 3 2 4
4 2 3
1 3 2 4
1 2 3 4
3 2 4
1 2 3 4
import csv
with open("np_krk.csv") as file:
reader = csv.reader(file)
candidates = next(reader)
results = {c: 0 for c in candidates}
for row in reader:
row_votes = [(i, int(row[i])) for i in range(len(row)) if row[i] != ""]
row_votes = sorted(row_votes, key=lambda t: t[1], reverse=True)[:3]
for index, _ in row_votes:
results[candidates[index]] += 1
print(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment