Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert array of tamil unicode values into tamil string in python with whitespaces?

Here is the list of Tamil unicode codepoints

[u'\u0b9a', u'\u0b9f', u'\u0bcd', u'\u0b9f', u'\u0b9a', u'\u0baa', u'\u0bc8', u'\u0baf', u'\u0bbf', u'\u0bb2', u'\u0bcd', u'\u0ba8', u'\u0bc7', u'\u0bb1', u'\u0bcd', u'\u0bb1', u'\u0bc1]

How can I convert it to readable string?

like image 346
chandrakanth duraisamy Avatar asked Mar 17 '12 05:03

chandrakanth duraisamy


People also ask

How do you change a Unicode to a string in Python?

To convert Python Unicode to string, use the unicodedata. normalize() function. The Unicode standard defines various normalization forms of a Unicode string, based on canonical equivalence and compatibility equivalence.

How do I convert Unicode to letter in Python?

In Python, the built-in functions chr() and ord() are used to convert between Unicode code points and characters. A character can also be represented by writing a hexadecimal Unicode code point with \x , \u , or \U in a string literal.

How will you convert an integer to a Unicode character in Python?

unichr() is named chr() in Python 3 (conversion to a Unicode character).


1 Answers

No conversion needed.

    >>> alist = [
            u'\u0b9a', u'\u0b9f', u'\u0bcd', u'\u0b9f', u'\u0b9a',
            u'\u0baa', u'\u0bc8', u'\u0baf', u'\u0bbf', u'\u0bb2',
            u'\u0bcd', u'\u0ba8', u'\u0bc7', u'\u0bb1', u'\u0bcd',
            u'\u0bb1', u'\u0bc1',
            ]
    >>> print u''.join(alist)
    சட்டசபையில்நேற்று
    >>> 

Update: Perhaps you want this:

>>> print u' '.join(alist)
ச ட ் ட ச ப ை ய ி ல ் ந ே ற ் ற ு

or this:

>>> import unicodedata
>>> for c in alist:
    print repr(c), c, unicodedata.category(c)


u'\u0b9a' ச Lo
u'\u0b9f' ட Lo
u'\u0bcd' ் Mn
u'\u0b9f' ட Lo
u'\u0b9a' ச Lo
u'\u0baa' ப Lo
u'\u0bc8' ை Mc
u'\u0baf' ய Lo
u'\u0bbf' ி Mc
u'\u0bb2' ல Lo
u'\u0bcd' ் Mn
u'\u0ba8' ந Lo
u'\u0bc7' ே Mc
u'\u0bb1' ற Lo
u'\u0bcd' ் Mn
u'\u0bb1' ற Lo
u'\u0bc1' ு Mc
>>> 
like image 71
John Machin Avatar answered Sep 23 '22 22:09

John Machin