Python 当满足特定条件时,从列表创建新列表
我想从另一个单词列表中创建一个新列表;当单词的某个条件满足时。在本例中,我想将所有长度为9的单词添加到一个新列表中 我使用了: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
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]