0

I have a list with some thousands strings. Some strings have & that should be replaced by and some strings have % that should be replaced for and so on. There are many rules.

There are some strings with this special character a(ring) that should be replaced by a lower case.

I am using the follow code:

brnd = 'Acne Studios Blå Konst'
print(brnd.lower().replace(' ','-').replace('.','').replace('%','').replace('\134','a'))

returns acne-studios-blå-konst
desired acne-studios-bla-konst

The a(ring) is still there. What am I missing here? Python 2.7.12

IgorAlves
  • 5,086
  • 10
  • 52
  • 83

1 Answers1

0

Try using the unicodedata module.

Demo:

import unicodedata
brnd = 'Acne Studios Blå Konst'
print unicodedata.normalize('NFD', unicode(brnd, 'utf-8')).encode('ascii', 'ignore').lower().replace(' ','-')

Output:

acne-studios-bla-konst
Rakesh
  • 81,458
  • 17
  • 76
  • 113
  • Hy Rakesh this what I am getting after copy your code: `SyntaxError: Non-ASCII character '\xc3' in file /home/ila/vhosts/crawler/bucky.py on line 6`. Line 6 is where a have the sentence `Acne Studios ...` – IgorAlves May 25 '18 at 13:27