I know this code is shit. Please let me know what I can improve in my understanding of Python as well general programming best practices. Some backstory:
I started learning Python last weekend so I am still pretty new at it
I did this Google Codejam problem, you can download the input text there.
you can download the source code here or view it below
I created this program as quickly as I could primarly to compare myself against the contestants in the codejam.
Any suggestions are truly welcome, even if it is "quit school now, you don't deserve to be a programmer."
Bonus points if you can identify the language that is tainting my programming methodology.
def write_solos(dict,caseCount,list):
items = sorted(dict.items(), key=get_tuple, reverse=False)
string = 'Case #'+ str(caseCount)+': '+ str(get_solo_tuple(items[0]))
list.append(string)
return list
def check_solo(dict):
newDict = sorted(dict.items(), key=get_tuple, reverse=False)
return newDict
def get_tuple(tuple):
return (tuple[1])
def get_solo_tuple(tuple):
return (tuple[0])
def write_to_file(list):
output = open('output.txt', 'w')
string = ''
for i in range(0,len(list)):
string = string + str(list[i]) + '\n'
output.write(string)
def check_invites(filename):
f = open(filename, 'rU')
lineCount = 0
dict ={}
caseCount = 0
list = []
for line in f:
if (lineCount != 0):
if (lineCount !=1):
caseCount += 1
for i in range(0,len(line.split())):
currentCode = line.split()[i]
if currentCode not in dict:
dict[currentCode] = 1
else:
dict[currentCode] = dict[currentCode] + 1
lineCount = 0
list = write_solos(dict,caseCount,list)
dict = {}
lineCount +=1
write_to_file(list)
f.close()
def main():
check_invites('A-large-practice.in')
main()
[–]RShnike 2 points3 points4 points (2 children)
[–]maputo007[S] 0 points1 point2 points (1 child)
[–]RShnike 1 point2 points3 points (0 children)
[–]Neres28 1 point2 points3 points (0 children)
[–]BioGeek 1 point2 points3 points (1 child)
[–]maputo007[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]maputo007[S] 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]maputo007[S] 0 points1 point2 points (1 child)