4

if you're looping though the chars a unicode string in python (2.x), say:

ak.sɛp.tɑ̃

How can you tell whether the current char is a combining diacritic mark?

For instance, the last char in the above string is actually a combining mark:

ak.sɛp.tɑ̃ --> ̃

hippietrail
  • 15,848
  • 18
  • 99
  • 158
ʞɔıu
  • 47,148
  • 35
  • 106
  • 149
  • Related question: [Algorithm to check for combining characters in Unicode - Stack Overflow](https://stackoverflow.com/questions/17051732/algorithm-to-check-for-combining-characters-in-unicode) – user202729 May 11 '23 at 14:42

1 Answers1

9

Use the unicodedata module:

import unicodedata
if unicodedata.combining(u'a'):
    print "is combining character"
else:
    print "is not combining"

these posts are also relevant

How do I reverse Unicode decomposition using Python?

What is the best way to remove accents in a Python unicode string?

Community
  • 1
  • 1
Joe Koberg
  • 25,416
  • 6
  • 48
  • 54