so I'm trying to open a text file with a poem and see how many times I can spell the word "GOOD" with the letter in the text file in each line, but I get the following error:
Traceback (most recent call last):
File "./soup.py", line 11, in <module>
print( "\n".join( [("Case #%d: %d" % (i, parse(file[i]))) for i in range(1, len(file))]))
File "./soup.py", line 7, in parse
d['O'] /= 2
KeyError: 'O'
source:
#!/usr/bin/python
def parse(string):
d = {'G' : 0, 'O' : 0, 'D' : 0}
d = {s: string.count(s) for s in string if s in d }
d['O'] /= 2
return min(d.values())
file = open("poem.txt").read().split('\n')
print( "\n".join( [("Case #%d: %d" % (i, parse(file[i]))) for i in range(1, len(file))]))
{c: string.count(c) for c in d}
.