mercredi 3 novembre 2021

Removing multiple item from a list for each criteria not being fulfilled [duplicate]

I need to build a function that takes a list and removes every item that doesn't meet all the criterias I've mentionned in it. The structure is the following :

def function(my_list):

    for element in my_list:
        if not criteria_1:
            my_list.remove(element)

        else:
            if not criteria_2:
                my_list.remove(element)

return my_list

And I do that for many criterias. The issue is that the list I get as a result contains elements that don't match the criterias I've specifically mentionned in the function. The expected is a list that contains only elements that match all the criterias.

Aucun commentaire:

Enregistrer un commentaire