I'm making a function that gets the top dog names in NYC from a text file and prints the top 10.
Here is my code:
for line in inputFile:
fields = line.split("\t")
nameList.append(fields[0])
nameDict = {}
for name in nameList:
if name not in nameDict:
nameDict[name] = 1
else:
nameDict[name] += 1
keyList = []
for name in nameDict:
keyList.append(name)
keyList.sort()
for name in keyList:
print(name, nameDict[name])
Here is an example of the text file:
dog_name gender breed birth dominant_color secondary_color third_color spayed_or_neutered guard_or_trained borough zip_code
Buddy M Afghan Hound Jan-00 BRINDLE BLACK n/a Yes No Manhattan 10003
Nicole F Afghan Hound Jul-00 BLACK n/a n/a Yes No Manhattan 10021
Here is what happens now with my code:
"Keaton," 1
"Lady,Princess,Prescott" 1
"cathalina," 1
A. 1
A.A. 1
ABBA 1
ABBESS 1
ABBEYROAD 1
ABERCROMBIE 1
ABIGALE 1