Remove spaces from value in a dictionary

def f(a):
    for item in a:
        c = item
        b = len(a[item])
        print('{} {}'.format(c,b))

I want to create a function f in python where you can print all keys and lengths of the keys’ associated values ​​in a dictionary, for example a={'A': 'hey you', 'B': 'hello'} should give us the output:

A 6
B 5

But with my code I get the output:

A 7
B 5

Because it count spaces in len(), how can I fix this? This is what I have tried so far but it gives me TypeError: string indices must be integers

def f(a):
    for item in a:
        c = item
        b = a[item]
        for i in b:
            if b[i] == ' ':
                return b.strip()
            else:
                return b
    print('{} {}'.format(c,len(b)))

Answer

In that case, use .replace()method to replace all the white spaces.:

len(a[item].replace(" ",''))
def f(a):
    for item in a:
        c = item
        b = len(a[item].replace(" ",''))
        print('{} {}'.format(c,b))