Skip to content

word_count: test mixed case #234

@behrtam

Description

@behrtam

I just saw a solution to the word_count exercise where my feeling was that this shouldn't pass all tests. There is already one mixed case test, but it has a specific word order so that this solution works.

def word_count(input):
    list = {}
    for word in input.split():
        if word in list:
            list[word]+=1
        elif word.lower() in list:
            list[word.lower()]+=1
        else:
            list[word]=1
    return list

>>> word_count('GO go Go')
{'GO': 1, 'go': 2}
>>> word_count('go Go GO')
{'go': 3}
>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions