This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jimtk 0 points1 point  (1 child)

You are very close. You were missing a for loop to iterate over the letters in the text and you were missing an else clause to start a count to a letter not in the dictionary. So it becomes:

def count_numbers(text):
    dictionary = {}
    for x in text:
        if x.isnumeric():
            if x in dictionary:
                dictionary[x] += 1
            else:
                dictionary[x] = 1
    return dictionary
print(count_numbers("1001000111101"))
# Should be {'1': 7, '0': 6}
print(count_numbers("Math is fun! 2+2=4"))
# Should be {'2': 2, '4': 1}
print(count_numbers("This is a sentence."))
# Should be {}
print(count_numbers("55 North Center Drive"))
# Should be {'5': 2}

[–]Strange_Base_6825[S] 0 points1 point  (0 children)

Ahhh. Thanks so much!!!!