Ignore the items in the ignore list by name in python -


i ignore items in ignore_list name in python. example consider

fruit_list = ["apple", "mango", "strawberry", "cherry", "peach","peach pie"] allergy_list = ["cherry", "peach"] good_list = [f f in fruit_list if (f.lower() not in allergy_list)] print good_list 

i good_list ignore "peach pie" because peach in allergy list , peach pie contains peach :-p

how about:

fruits = ["apple", "mango", "strawberry", "cherry", "peach","peach pie"] allergies = ["cherry", "peach"]  okay = [fruit fruit in fruits if not any(allergy in fruit.split() allergy in allergies)] # ['apple', 'mango', 'strawberry'] 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -