Python read from a text file and create/return dictionary values
<p>I am having trouble creating a program that reads from text which maps a word and returns values. How would I write a code to read a text file and spit back a dictionary data structure. The text file is a lot longer than 3, but here is an example.</p>

<pre><code>Mary        21.0          25.0
Carson      25.0          27.0
Blair       22.0          10.0
</code></pre>

<p>and if I were to </p>

<pre><code>&gt;&gt;&gt; dict['Mary']
[21.0, 25.0]
</code></pre>

<p>and then</p>

<pre><code>&gt;&gt;&gt; dict['Mary'][0]
21.0

&gt;&gt;&gt; dict['Mary'][1]
25.0
</code></pre>

<p>Thanks.</p>

<p>You are looking for a simple snippet like this</p>

<pre><code>dic = {}
with open(filename, 'r') as f:
    for line in f:
        info = line.split('\t')
        dic[info[0]] = info[1:]
</code></pre>

<p>It is just a model, adapt that to your needs.</p>

python file dictionary