Skip to content

Instantly share code, notes, and snippets.

@Orangestar12
Last active February 21, 2016 00:41
Show Gist options
  • Save Orangestar12/4c46adfdd85cddb4cd0a to your computer and use it in GitHub Desktop.
Save Orangestar12/4c46adfdd85cddb4cd0a to your computer and use it in GitHub Desktop.
It's relatively slow but it works.
# -*- coding: utf-8 -*-
import csv
Filename = input('CSV Filename:')
with open(Filename, newline='') as csvdata:
csvFile = csv.reader(csvdata)
csvList = []
for row in csvFile:
csvList.append(row)
print('How many rows down does the data start?')
Y = int(input(''))
print('How many columns across does the data start?')
X = int(input(''))
i = 0
while i < X:
for x in csvList:
del x[0]
i += 1
i = 0
while i < Y:
del csvList[0]
i += 1
Total = len(csvList)
def returnGreatest(l):
greatest = {}
for x in l:
if x[0] in greatest:
greatest[x[0]] += 1
else:
greatest[x[0]] = 1
largest = 0
largeIndex = []
for x in greatest:
if greatest[x] > largest:
largest = greatest[x]
largeIndex = [x]
elif greatest[x] == largest:
largeIndex.append(x)
smallest = 99999999999999999999999
smallIndex = []
for x in greatest:
if greatest[x] < smallest:
smallest = greatest[x]
smallIndex = [x]
elif greatest[x] == smallest:
smallIndex.append(x)
return [largeIndex, largest], [smallIndex, smallest]
i = 1
while True:
print('Round', i)
a, b = returnGreatest(csvList)
print('The winner(s) this round was/were {} with {} votes.'.format(a[0], a[1]))
if float(a[1]) > Total/2 and len(a[0]) == 1:
print('{} has won majority! ({} of {} votes.)'.format(a[0], a[1], Total))
break
print('The entry/entries {} have been removed (Last place with {} votes.)'.format(b[0], b[1]))
for x in b[0]:
for y in csvList:
if x in y:
y.remove(x)
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment