String accents are special string characters adapted from languages of other accents. In this article, we are going to remove ascents from a string.
Examples:
Input: orčpžsíáýd
Output: orcpzsiayd
Input: stävänger
Output: stavanger
We can remove accents from the string by using a Python module called Unidecode. This module consists of a method that takes a Unicode object or string and returns a string without ascents.
Syntax:
output_string = unidecode.unidecode(target_string )
Below are some examples which depict how to remove ascents from a string:
Example 1:
Python3
# import required moduleimport unidecode# assign stringstring = "orčpžsíáýd"# display original stringprint('\nOriginal String:', string)# remove ascentsoutputString = unidecode.unidecode(string)# display new stringprint('\nNew String:', outputString) |
Output:
Original String: orčpžsíáýd New String: orcpzsiayd
Example 2:
Python3
# import required moduleimport unidecode# assign stringstring = "stävänger"# display original stringprint('\nOriginal String:', string)# remove ascentsoutputString = unidecode.unidecode(string)# display new stringprint('\nNew String:', outputString) |
Output:
Original String: stävänger New String: stavanger
Example 3:
Python3
# import required moduleimport unidecode# assign stringstringList = ["hell°", "tromsø", "stävänger", "ölut"]# display original stringprint('\nOriginal List of Strings:\n', stringList)for i in range(len(stringList)): # remove ascents stringList[i] = unidecode.unidecode(stringList[i])# display new stringprint('\nNew List of Strings:\n', stringList) |
Output:
Original List of Strings: ['hell°', 'tromsø', 'stävänger', 'ölut'] New List of Strings: ['helldeg', 'tromso', 'stavanger', 'olut']
