cyc*_*out 3 python unicode tuples list python-2.7
将元组中的值从unicode转换为字符串的最佳方法是什么,当元组在列表中时,是否可以在不循环的情况下完成?
unicodedata.normalize('NKFD', x)只能采取unicode,而不是元组.数据集还包括浮点值.
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
Run Code Online (Sandbox Code Playgroud)
如何将所有这些价值观作为一个str?
我不确定有没有办法在不使用循环/列表理解的情况下转换它.
我会使用该map函数来完成此任务,请参阅:
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
Run Code Online (Sandbox Code Playgroud)