-
Notifications
You must be signed in to change notification settings - Fork 0
/
txt_to_csv.py
29 lines (23 loc) · 938 Bytes
/
txt_to_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import csv
# Get rid of spaces and newline characters
def strip(s):
return s.strip()
def main():
results = []
with open("2020_2021_results.txt") as f:
lines = list(map(strip, f.readlines()))
for line in lines:
visit_team, visit_points, home_team, home_points = line.split(",")
home_points = int(home_points)
visit_points = int(visit_points)
win_team = home_team if home_points > visit_points else visit_team
lose_team = home_team if home_points < visit_points else visit_team
win_loc = "H" if home_points > visit_points else "V"
results.append((win_team, lose_team, win_loc))
header = ["WinTeam", "LoseTeam", "WinLoc"]
with open("2020_2021_results.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
writer.writerows(results)
if __name__ == "__main__":
main()