Confused about looping through list of people in Python
<p>I'm having issues with an exercise that is asking me to loop through my list of people and print everything that I know about each person while using a dictionary for each person. I'm trying to start out by just getting Python to accept and loop through my dictionaries, but whenever I try to run my code, I get an error message stating: "Value Error: too many values to unpack. (expected 2)"</p>

<pre><code>dictionaries_v = {

    'first_name': 'victor',
    'last_name': 'croc',
    'age': 21,
    'city': 'new york',
    }

dictionaries_c = {

    'first_name': 'charmy',
    'last_name': 'bee',
    'age': 8,
    'city': 'new york',
    }

dictionaries_e = {

    'first_name': 'espio',
    'last_name': 'armadilo',
    'age': 15,
    'city': 'new york',
    }

people = ['dictionaries_v', 'dictionaries_c', 'dictionaries_e']

for key, value in people:

    print( "\n" + key + ": " + value)
</code></pre>

<p>Thank you for your time.</p>

<p>Your first problem is that your list is holding three <em>strings</em>. Notice how you wrapped quotes around it. So when you iterate over your list, you will most definitely not be getting the dictionary you expect. </p>

<p>Secondly, <code>people</code> is a <code>list</code>. So, when you iterate your list, your iterator will hold the dictionary through each iteration. </p>

<p>Knowing this, you simply need to iterate over your list, like any other list: </p>

<pre><code>people = [dictionaries_v, dictionaries_c, dictionaries_e]
for d in people:
    print(d)
</code></pre>

<p>Your output will look like:</p>

<pre><code>{'last_name': 'croc', 'age': 21, 'first_name': 'victor', 'city': 'new york'}
{'last_name': 'bee', 'age': 8, 'first_name': 'charmy', 'city': 'new york'}
{'last_name': 'armadilo', 'age': 15, 'first_name': 'espio', 'city': 'new york'}
</code></pre>

<p>To get specific information from your dictionary, you just use the key in each iteration. Simple example:</p>

<pre><code>for d in people:
    print(d['last_name'])
</code></pre>

python