Skip to content

Instantly share code, notes, and snippets.

@kendhia
Created December 18, 2016 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendhia/33c24641a760961fa64c2412aa4cfab6 to your computer and use it in GitHub Desktop.
Save kendhia/33c24641a760961fa64c2412aa4cfab6 to your computer and use it in GitHub Desktop.
import csv
def retrieveData(file_name_str, list_of_nominees) :
csvReader = csv.reader(open(file_name_str))
electtionResultsList = list(csvReader)
calculatedVotes = []
for nomineeName in list_of_nominees:
for i in range(len(electtionResultsList[0])):
if (electtionResultsList[0][i] == nomineeName ) :
for j in range(1, len(electtionResultsList)):
calculatedVotes.append(electtionResultsList[j][i])
i = 0
return calculatedVotes
print(retrieveData("ElectionUSA2012.csv", ["Obama","Romney","Johnson","Stein"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment