import csv from collections import Counter #This used to be named rank choice count, but when I had problems with the ignoring winners thing I pasted the code I had in chatgpt and instead of helping me it just continuously spit back election fact checks. def count_this_shit(csv_file, ignored_options=None): if ignored_options is None: ignored_options = [] # Maybe I'm just shitty at python, but it didnt work unless I started empty then appended. #ignored_options.append("Option 10") #ignored_options.append("Option 15") #ignored_options.append("Option 44") ignored_options = [option for option in ignored_options] #So instead of comma seperation for vote counts, I had > and 2 spaces seperating since I wanted the print back to show that. I made the vote page in 45 minutes, sssh. with open(csv_file, 'r') as file: reader = csv.DictReader(file) votes = [row['Ranked Options'].split(' > ') for row in reader] votes = [[option for option in vote] for vote in votes] votes = [[option for option in vote if option not in ignored_options] for vote in votes] all_candidates = {option for vote in votes for option in vote} total_votes = len(votes) rounds = 1 while True: print(f"Round {rounds}:") first_choice_counts = Counter(vote[0] for vote in votes if vote) #list options even if they have no first votes. I figured if anyone ran this code later they might be confused if it didnt print all in the first round. for candidate in all_candidates: if candidate not in first_choice_counts: first_choice_counts[candidate] = 0 total_first_votes = sum(first_choice_counts.values()) for option, count in sorted(first_choice_counts.items()): print(f" {option}: {count} ({count / total_first_votes:.1%})") #check for more than 50% for option, count in first_choice_counts.items(): if count > total_first_votes / 2: print(f"\nMajority: {option}\n") return option #womp womp min_votes = min(first_choice_counts.values()) eliminated_options = [option for option, count in first_choice_counts.items() if count == min_votes] print(f"\nYeet: {', '.join(eliminated_options)}\n") #YEET votes = [[choice for choice in vote if choice not in eliminated_options] for vote in votes] all_candidates -= set(eliminated_options) #Idk what I'd do if there was a tie. Sudden death discord poll? if not any(votes): print("\nfuckin tie.\n") return None rounds += 1 csv_file = 'votes.csv' # Part of it was comma seperated it's technically a csv lol winner = count_this_shit(csv_file) print(f"You're Winner: {winner}")