Skip to content Skip to sidebar Skip to footer

Create A New List From A List When A Certain Condition Is Met

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 list. I h

Solution 1:

Sorry, realized you wanted length, 9, not length 9 or greater.

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

Solution 2:

Try:

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

Solution 3:

Solution 4:

Try this:

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

Post a Comment for "Create A New List From A List When A Certain Condition Is Met"