Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
remove_accents solution in Clear category for Remove Accents by dannedved
def checkio(in_string):
for i, char in enumerate(in_string):
# A character whose unicode integer is larger than 127 could be an accented character or a combining accent.
if ord(char) > 127:
# We make use of "namereplace" error raised for ASCII encoding.
# The character is converted to a short description, such as "\N{LATIN SMALL LETTER E WITH ACUTE}."
# We convert this description from "byte" type to "string" type.
name_replace_str = str(char.encode("ascii", "namereplace"))
# Accented letters contain the word "LETTER" in their "namereplace" descriptors.
# The unaccented letter is given as the fourth word of the said descriptor.
if "LETTER" in name_replace_str:
# The "namereplace" description is always capitalized; we check if the unaccented letter should be converted to lowercase.
# Lowercase letters are labeled by the word "SMALL" in their "namereplace" descriptors.
if "SMALL" in name_replace_str:
in_string = in_string.replace(char, name_replace_str.split()[3].lower())
else:
in_string = in_string.replace(char, name_replace_str.split()[3])
# Stand-alone accents contain the word "MARK" in their "namespace" descriptors.
# These characters are omitted.
elif "MARK" in name_replace_str:
in_string = in_string.replace(char, "")
return in_string
May 12, 2020
Comments: