我有一个这样的清单:
[[(u'hello@hello.com',)], [(u'hello@hello.com',)]]
我想将其转换为:
[['hello@hello.com'], ['hello@hello.com']]
我该怎么做?
另一个例子:
输入:[[(u'hello',), (u'hello',)], [(u'hello',)]]
应该返回[['hello@hello.com', 'hello@hello.com'], ['hello@hello.com']]
答案 0 :(得分:0)
new = [[j[0].encode('utf-8') for j in i] for i in old]
UTF-8只是一个例子,您应该确保正确编码。
答案 1 :(得分:0)
test = [[(u'hello',), (u'hello',)], [(u'hello',)]]
for i, part_i in enumerate(test):
for j, part_j in enumerate(part_i):
test[i][j] = str(part_j[0])
或者,如果您更喜欢单行版本:
test = [[(u'hello',), (u'hello',)], [(u'hello',)]]
result = [[str(j[0]) for j in i] for i in test]