Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.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_Append_Conditional Statements - Fatal编程技术网

Python 当满足特定条件时,从列表创建新列表

Python 当满足特定条件时,从列表创建新列表,python,list,append,conditional-statements,Python,List,Append,Conditional Statements,我想从另一个单词列表中创建一个新列表;当单词的某个条件满足时。在本例中,我想将所有长度为9的单词添加到一个新列表中 我使用了: resultReal = [y for y in resultVital if not len(y) < 4] 抱歉,意识到您想要的是长度9,而不是长度9或更大 newlist = [word for word in words if len(word) == 9] 尝试: 新列表=[] 对于resultVital中的项目: 如果长度(项目)==9: newl

我想从另一个单词列表中创建一个新列表;当单词的某个条件满足时。在本例中,我想将所有长度为9的单词添加到一个新列表中

我使用了:

resultReal = [y for y in resultVital if not len(y) < 4]

抱歉,意识到您想要的是长度9,而不是长度9或更大

newlist = [word for word in words if len(word) == 9]
尝试:

新列表=[] 对于resultVital中的项目: 如果长度(项目)==9: newlist.append(item)尝试以下操作:

newlist = [word for word in words if len(word) == 9]
试试这个:

list= [list_word for list_word in words if len(list_word) == 1]

检查编辑页面右下方的格式提示。请正确设置代码的格式,以便于阅读。
newlist = [word for word in words if len(word) == 9]
list= [list_word for list_word in words if len(list_word) == 1]