在列表中拆分列表

我在列表中有一个列表,如下所示:

ls = [["Test1\t\t\t\t\tValue1"],["Test2\t\t\t\t\t\t\tValue2"]]

# My current code is 
new = [i.split("\t") for i in ls]

print(new)

所需的输出:[[“ Test1”,“ Value1”],[“ Test2”,“ Value2]]

它似乎不起作用,测试1的当前输出显示为[“ Test 1 \ t \ t \ t \ t”,“ Value 1”]。

我正在使用Python v3.8

评论
oiusto
oiusto
# empty string's evaluates to false, skip.

new = [[j for j in i[0].split("\t") if j] for i in ls]

输出

[['Test1', 'Value1'], ['Test2', 'Value2']]
点赞
评论