Create a new list from a list when a certain condition is met

后端 未结 4 1049
迷失自我
迷失自我 2020-12-14 20:43

I want to make a new list from another list of words; when a certain condition of the word is met. In this case I want to add all words that have the length of 9 to a new li

4条回答
  •  臣服心动
    2020-12-14 21:29

    Try:

    newlist = []
    for item in resultVital:
        if len(item) == 9:
            newlist.append(item)

提交回复
热议问题