如何将2个列表与元素并排加入?例如:
list1 = ["they" , "are" ,"really" , "angry"]
list2 = ["they" , "are" ,"seriously" , "angry"]
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
list3 = [("they","they"),("are","are"),("really","seriously"),("angry","angry")]
Run Code Online (Sandbox Code Playgroud)
上面看起来像一个列表元组,如果上面的列表是连续每个单词的列,我如何将list2追加到list1?
Ter*_*ryA 10
用途zip():
>>> list1 = ["they" , "are" ,"really" , "angry"]
>>> list2 = ["they" , "are" ,"seriously" , "angry"]
>>> list3 = zip(list1, list2)
>>> list3
[('they', 'they'), ('are', 'are'), ('really', 'seriously'), ('angry', 'angry')]
Run Code Online (Sandbox Code Playgroud)