Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to create a new list only with words that end with "ant" and have 7 caracters?

+8 votes
asked Nov 6, 2021 by Lo Canu (250 points)

This is the list that we start with:

liste_ant = ["enfant", "bonjour", "éléphant", "aidant", "saumon", "amusant", "blessant", "piscine", "broyant", "carburant", "devant", "vibrant"]

We have to create this new list:

new_list = [ "amusant""broyant""devant""vibrant"]

2 Answers

0 votes
answered Nov 8, 2021 by Peter Minarik (55,660 points)

Your similar question has been answered already. Now you just have to add one more check: how long is the string you're examining. Go online, do some research! ;) (Help: look for the function len())

+1 vote
answered Nov 8, 2021 by Anish Joshi (160 points)
liste_ant = ["enfant", "bonjour", "éléphant", "aidant", "saumon", "amusant", "blessant", "piscine", "broyant", "carburant", "devant", "vibrant"]
def filterant(val):
    if "ant" in val:
        if len(val) == 7:
            return val
        
def special(list1):
    return list(filter(filterant,list1))
    
print(special(liste_ant))
commented Nov 8, 2021 by Peter Minarik (55,660 points)
First of all, OP seems to be asking us to do their homework...

Second, your solution is for any 7 character length strings that contain "ant", not that end with "ant".
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...