What is the best way to convert the values in tuples from unicode to string, when the tuples are in a list, can it be done without looping?
unicodedata.normalize('NKFD', x) can only take unicode, not a tuple. The dataset also includes float values.
unicode_tuple_list = [(u'text in unicode', u'more unicode'), (u'more text in unicode', u'even more unicode')]
print type(unicode_tuple_list) # list - keep as list
print type(unicode_tuple_list[0]) # tuple - keep as tuple
print type(unicode_tuple_list[0][0]) # unicode
How can all these values be made a str?
I'm not sure there is a way to convert this without using a loop/list comprehension.
I would use the map function to accomplish this, see:
unicode_tuple_list = [(u'text in unicode', u'more unicode'), (u'more text in unicode', u'even more unicode')]
string_tuple_list = [tuple(map(str,eachTuple)) for eachTuple in unicode_tuple_list]
print string_tuple_list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With