Skip to content

Latest commit

 

History

History
35 lines (18 loc) · 647 Bytes

char_to_ascii.md

File metadata and controls

35 lines (18 loc) · 647 Bytes

CodeWars Python Solutions


char_to_ascii

Take a string and return a hash with all the ascii values of the characters in the string. Returns nil if the string is empty. The key is the character, and the value is the ascii value of the character. Repeated characters are to be ignored and non-alphebetic characters as well.


Given Code

def char_to_ascii(string):
    pass

Solution

def char_to_ascii(string):
    return {c:ord(c) for c in string if c != " " and c.isalpha()} if len(string) else None

See on CodeWars.com