Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何拆分列表中元组的所有第一个元素?(Python)_Python_List_Tuples - Fatal编程技术网

如何拆分列表中元组的所有第一个元素?(Python)

如何拆分列表中元组的所有第一个元素?(Python),python,list,tuples,Python,List,Tuples,我制作了一个名为conditionList的列表,如下所示: ('I'm a man.', 2, 5, 10), ('I'm 20 years old', 6, 8, 10), ('This is just another sentence', 5, 6 10) 此条件列表是4个列表的zip函数的结果: conditionlist = zip(sentence, variable1, variable2, variable3) 因此,列表中的每个元素都由一个句子和三个数字组成。 但是,我需要

我制作了一个名为conditionList的列表,如下所示:

('I'm a man.', 2, 5, 10), ('I'm 20 years old', 6, 8, 10), ('This is just another sentence', 5, 6 10)
条件列表
是4个列表的zip函数的结果:

conditionlist = zip(sentence, variable1, variable2, variable3)
因此,列表中的每个元素都由一个句子和三个数字组成。 但是,我需要一个函数,该函数将产生以下列表:

('I', 2, 5, 10), ('am', 2, 5, 10), ('a', 2, 5, 10), ('man.', 2, 5, 10), ('I', 6, 8, 10) etc.
这样,每个单词都与它们所属句子的变量相关联

如何从条件列表转到所需列表


谢谢。

你可能是打字错误,你只需要理解和
str.split

>>> l
(("I'm a man.", 2, 5, 10),
 ("I'm 20 years old", 6, 8, 10),
 ('This is just another sentence', 5, 6, 10))
>>> [(i, j, k, m) for p, j, k, m in l for i in p.split()]
[("I'm", 2, 5, 10),
 ('a', 2, 5, 10),
 ('man.', 2, 5, 10),
 ("I'm", 6, 8, 10),
 ('20', 6, 8, 10),
 ('years', 6, 8, 10),
 ('old', 6, 8, 10),
 ('This', 5, 6, 10),
 ('is', 5, 6, 10),
 ('just', 5, 6, 10),
 ('another', 5, 6, 10),
 ('sentence', 5, 6, 10)]

如何转换为
?谢谢你的回答。我是python新手,您能再解释一下建议的代码是如何工作的吗?