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>You have some indentation problems, clearly, but the main problems are that you are taking the length of the dictionary (getting the number of keys) not taking the length of the key. You also have some bad logic.</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:
    length = len(employeeDict)  # &lt;---- indent this
    if length &gt;= 5:    # &lt;--- greater than 4
        # convert string to number, add money, convert back to string
        employeeDict[x] = str(int(employeeDict[x]) + 1000 * (length))

print employeeDict[x]
</code></pre>

python dictionary count