将列表分成两个独立变量

时间:2018-10-04 06:31:33

标签: python python-3.x list variables dataframe

我有一个具有两个属性的列表,我想在一个新的数据框中将其分成两个独立的变量,例如:

dataframe = (var1, var2)
var1 = client, say, management, take
var2 = NN, VBP, NN, VB

现在我的列表:

print(Grammer[:10])
[('client', 'NN'), ('say', 'VBP'), ('management', 'NN'), ('take', 'VB'), ('decission', 'NN'), ('submitted', 'VBN')]

1 个答案:

答案 0 :(得分:1)

使用zip +开箱:

lst = [('client', 'NN'), ('say', 'VBP'), ('management', 'NN'), ('take', 'VB'), ('decission', 'NN'), ('submitted', 'VBN')]

var1, var2 = zip(*lst)

print(var1)  # ('client', 'say', 'management', 'take', 'decission', 'submitted')                                                       
print(var2)  # ('NN', 'VBP', 'NN', 'VB', 'NN', 'VBN')