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>Give this a try and analyse it :</p>

<p></p>

<pre><code>employees = {"John":10000, "Daren":10000, "Graham":10000}

for name in employees:
    if len(name) &gt; 5:
        employees[name] += 1000 * len(name)
</code></pre>

<p>If you have to stick with the string values you can do this :</p>

<p></p>

<pre><code>employees = {"John":"10000", "Daren":"10000", "Graham":"10000"}

for name in employees:
    if len(name) &gt; 5:
        employees[name] = str(int(employees[name]) + 1000 * len(name))
</code></pre>

python dictionary count