Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a python version of JavaScript's String.fromCharCode?

Tags:

python

String.fromCharCode returns a string based on a list of unicode codepoint values. @see reference

Is there an analog in Python ?

like image 437
Frankie Ribery Avatar asked Jun 21 '11 09:06

Frankie Ribery


People also ask

What is string fromCharCode ()?

The String. fromCharCode() method converts Unicode values to characters. The String. fromCharCode() is a static method of the String object. The syntax is always String.

How does fromCharCode work?

The fromCharCode() method accepts a sequence of Unicode values. These Unicode values are UTF-16 values (16-bit integers between 0 and 65535) that are converted to characters and concatenated together in a string. This resulting string is then returned by the fromCharCode() method.

What is charCodeAt?

The charCodeAt() method returns the Unicode of the character at a specified index (position) in a string. The index of the first character is 0, the second is 1, .... The index of the last character is string length - 1 (See Examples below). See also the charAt() method.


1 Answers

You can use this: ''.join(map(unichr, lst))

Example:

''.join(map(unichr, [65,66,67])) # outputs ABC
like image 108
DrTyrsa Avatar answered Nov 15 '22 16:11

DrTyrsa