Jan-10-2021, 11:48 AM
Hey everyone, i'm trying filter items out of a list, which contains specific characters.
i tried to do it like shown below, but it is not doing what i expect it to do. instread of returning the list items, which contain "a" and "c", it gives me any item which has eighter an "a" or a "c" in it.
what am i doing wrong here? or is there a better way to do it? Happy for any help!
i tried to do it like shown below, but it is not doing what i expect it to do. instread of returning the list items, which contain "a" and "c", it gives me any item which has eighter an "a" or a "c" in it.
what am i doing wrong here? or is there a better way to do it? Happy for any help!
list = ["bc", "ad", "ac", "cpd"]
new_list =[]
for x in list:
if ("a" and "c") in x:
new_list.append(x)
print (new_list)Output:['bc', 'ac', 'cpd']
