 <p><code>"hunger"</code> isn't in the dictionary (that's what the <code>KeyError</code> tells you). The problem is probably your <code>make_happiness_table</code> function. I don't know if you've posted the full code or not, but it doesn't really matter. At the end of the function, you return an <em>empty dictionary</em> (<code>{}</code>) regardless of what else went on inside the function.</p> <p>You probably want to open your file inside that function, create the dictionary and return it. For example, if your csv file is just 2 columns (separated by a comma), you could do:</p> <pre><code>def make_happiness_table(filename): with open(filename) as f: d = dict( line.split(',') for line in f ) #Alternative if you find it more easy to understand #d = {} #for line in f: # key,value = line.split(',') # d[key] = value return d </code></pre>