The Wayback Machine - https://web.archive.org/web/20220205043209/https://www.geeksforgeeks.org/how-to-remove-string-accents-using-python-3/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to remove string accents using Python 3?

  • Difficulty Level : Easy
  • Last Updated : 02 Jul, 2021

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 module
import unidecode
 
# assign string
string = "orčpžsíáýd"
 
# display original string
print('\nOriginal String:', string)
 
# remove ascents
outputString = unidecode.unidecode(string)
 
# display new string
print('\nNew String:', outputString)

Output:

Original String: orčpžsíáýd

New String: orcpzsiayd

Example 2:

Python3




# import required module
import unidecode
 
# assign string
string = "stävänger"
 
# display original string
print('\nOriginal String:', string)
 
# remove ascents
outputString = unidecode.unidecode(string)
 
# display new string
print('\nNew String:', outputString)

Output:

Original String: stävänger

New String: stavanger

Example 3:

Python3




# import required module
import unidecode
 
# assign string
stringList = ["hell°",  "tromsø",  "stävänger", "ölut"]
 
# display original string
print('\nOriginal List of Strings:\n', stringList)
 
for i in range(len(stringList)):
    # remove ascents
    stringList[i] = unidecode.unidecode(stringList[i])
 
# display new string
print('\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']

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!