lundi 6 août 2018

Two conditions loop python

I have data as below

lst = ['abs', '@abs', '&abs']

I need to replace all parts with @ or &. I do like this

new = []
simbol1 = '@'
simbol2 = '&'
for item in lst:
    if simbol1 not in item:
        if simbol2 not in item:
            new.append(item)

But is there more simple way for this loop? I tried like this

lst = ['abs', '@abs', '&abs']
new = []
simbol1 = '@'
simbol2 = '&'
for item in lst:
    if any([simbol1 not in item , simbol2 not in item]):
        new.append(item)

But i get

new
['abs', '@abs', '&abs']

What is a correct way to use multiple conditions in this case?

Aucun commentaire:

Enregistrer un commentaire