Writing a table with values for several years as a dictionary?
<p>I have a table I want to write as a Python code, but I'm stuck and can't figure out how to do it.</p>

<p>I have a table with data for two years (1991 and 1992), and different values for each year (men: 35 (1991) and 42 (1992), women: 38 (1991), 39 (1992) and children: 15 (1991), 10 (1992).</p>

<p>What I want is to be able to write one variable (dictionary) in python that makes me able to search for a specific value in a specific year (ex: men(1992) = 42).</p>

<p>My best suggestion so far is to make a dictionary including tuples in something like this:</p>

<pre><code>people = {
    'year': (1991, 1992),
    'men': (35, 42),
    'women': (38, 39),
    'children': (15, 10)
    }
</code></pre>

<p>But this obviously not make it possible to search for both specific values in a specific year.</p>

<p>You want a nested dict:</p>

<pre><code>people = {
    "men": {
        1991: 35,
        1992: 42
    },
    "women": {
        1991: 38,
        1992: 39
    },
    "children": {
        1991: 15,
        1992: 10
    }
}
</code></pre>

<p>Now you can do <code>people['men'][1991]</code> to get the result 35.</p>

python dictionary tuples