Skip to content

Latest commit

 

History

History
36 lines (20 loc) · 615 Bytes

Count_characters_in_your_string.md

File metadata and controls

36 lines (20 loc) · 615 Bytes

CodeWars Python Solutions


Count characters in your string

The main idea is to count all the occurring characters(UTF-8) in string. If you have string like this aba then the result should be { 'a': 2, 'b': 1 }

What if the string is empty ? Then the result should be empty object literal { }

For C#: Use a Dictionary<char, int> for this kata!


Given Code

def count(string):
    pass

Solution

def count(string):
    return {c:string.count(c) for c in string}

See on CodeWars.com