-7

我有一个这样的列表:

  [[(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']]

4

2 回答 2

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]
于 2013-03-19T13:17:07.467 回答
0
new = [[j[0].encode('utf-8') for j in i] for i in old]

UTF-8 只是一个例子,你真的应该确保你得到正确的编码。

于 2013-03-19T12:50:18.707 回答