I think you need like this,
print [unicode(val,'utf-8') for val in l]
[u'love song', u'cooki monster definit medal gold card mcdonald', u'c start cup', u'c', u'h help bc cooki moster gott help', u'cooki monster get diabet', u'lll']
Note: Answer provided for python 2 version As per Austin commented, Literal strings are unicode by default in Python 3. So you don't need to convert externally.
Answer from Mohamed Thasin ah on Stack OverflowEvery codepoint has a name, so you are effectively asking for the Unicode standard list of codepoint names (as well as the *list of name aliases, supported by Python 3.3 and up).
Each Python version supports a specific version of the Unicode standard; the unicodedata.unidata_version attribute tells you which one for a given Python runtime. The above links lead to the latest published Unicode version, replace UCD/latest in the URLs with the value of unicodedata.unidata_version for your Python version.
Per codepoint, the unicodedata.name() function can tell you the official name, and unicodedata.lookup() gives you the inverse (name to codepoint).
If you want a list of all unicode character names, consider downloading the Unicode Character Database.
It is included in the base repositories of many linux distributions (ex. "unicode-ucd" on RHEL).
The package includes NamesList.txt, which contains the exhaustive list of unicode character names.
Caution: NamesList.txt need some times to be downloaded (size > 1.5 MB).
Example:
21FE RIGHTWARDS OPEN-HEADED ARROW
21FF LEFT RIGHT OPEN-HEADED ARROW
@@ 2200 Mathematical Operators 22FF
@@+
@ Miscellaneous mathematical symbols
2200 FOR ALL
= universal quantifier
2201 COMPLEMENT
x (latin letter stretched c - 0297)
2202 PARTIAL DIFFERENTIAL
2203 THERE EXISTS
= existential quantifier
2204 THERE DOES NOT EXIST
: 2203 0338
2205 EMPTY SET
= null set
* used in linguistics to indicate a null morpheme or phonological "zero"
x (latin capital letter o with stroke - 00D8)
x (diameter sign - 2300)
~ 2205 FE00 zero with long diagonal stroke overlay form
Literal strings are unicode by default in Python3.
Assuming that text is a bytes object, just use text.decode('utf-8')
unicode of Python2 is equivalent to str in Python3, so you can also write:
str(text, 'utf-8')
if you prefer.
What's new in Python 3.0 says:
All text is Unicode; however encoded Unicode is represented as binary data
If you want to ensure you are outputting utf-8, here's an example from this page on unicode in 3.0:
b'\x80abc'.decode("utf-8", "strict")
try applying unicode to its elements
>>> lst=['Justice league', 'Avenger']
>>> map(unicode,lst)
[u'Justice league', u'Avenger']
Obviously we are talking about Python 2 only, since literal strings are unicode by default in Python 3
Have a look at this Q&A on the same subject
Use the built in unicode function with a list comprehension:
x = ['Justice league', 'Avenger']
answer = [unicode(item) for item in x]
Encode each value in the list to a string:
[x.encode('UTF8') for x in EmployeeList]
You need to pick a valid encoding; don't use str() as that'll use the system default (for Python 2 that's ASCII) which will not encode all possible codepoints in a Unicode value.
UTF-8 is capable of encoding all of the Unicode standard, but any codepoint outside the ASCII range will lead to multiple bytes per character.
However, if all you want to do is test for a specific string, test for a unicode string and Python won't have to auto-encode all values when testing for that:
u'1001' in EmployeeList.values()
[str(x) for x in EmployeeList] would do a conversion, but it would fail if the unicode string characters do not lie in the ascii range.
>>> EmployeeList = [u'1001', u'Karick', u'14-12-2020', u'1$']
>>> [str(x) for x in EmployeeList]
['1001', 'Karick', '14-12-2020', '1$']
>>> EmployeeList = [u'1001', u'करिक', u'14-12-2020', u'1$']
>>> [str(x) for x in EmployeeList]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)