Counting number of characters in a key in a dictionary
<p>For homework I have been set the following:</p>

<p>Build a dictionary with the names from myEmployees list as
keys and assign each employee a salary of 10 000 (as value). Loop over the dictionary
and increase the salary of employees which names have more than four
letters with 1000 * length of their name. Print the dictionary contents before
and after the increase.</p>

<p>I can't figure out how to do it.</p>

<p>This is what I've come up with so far.</p>

<pre><code>employeeDict = {"John":'10,000', "Daren":"10,000", "Graham":"10,000", "Steve":"10,000", "Adren":"10,000"}

say = 'Before increase'
print say
print employeeDict

say1 = 'After increase'
print say1

for x in employeeDict:
x = len(employeeDict)
if x &gt; 5:
    print employeeDict[x]
</code></pre>

<p>This should give you what your looking for.</p>

<pre><code>employeeDict = {"John":10000, "Daren":10000, "Graham":10000, "Steve":10000, "Adren":10000}
print "Before increase"
print employeeDict

for name, salary in employeeDict.items():
    if len(name) &gt; 4:
        employeeDict[name] = salary + len(name) * 1000
print "After increase"
print employeeDict
</code></pre>

<p>You had a few problems in your version.</p>

<ul>
<li>Your idention for your for-loop was not correct</li>
<li>You were getting the length of the dictionary and not the length of the keys <strong>in</strong> the dictionary.</li>
<li>You should make the values in your dictionary floats/integers.</li>
</ul>

<p>Also note, I believe your homework said if the name was <strong>longer than four characters</strong>. So i used 4 instead of five.</p>

python dictionary count