I have one dictionary and one string, and one function that i wanted to return "y", but for now could return "y" or "z":
import re
def find_my_keyword():
dict_colour = {
"x": ["back", "blue", "green"],
"y": ["yellow", "white", "green"],
"z": ["yellow", "white"]
}
str1 = "I have yellow, green and white"
for colour, keywords in dict_colour.items():
if all(re.search(kw, str1) for kw in keywords):
return colour
Is there any way to add new array in my z list like not green:
"z": ["yellow", "white", =! "green"] ?
Or is any library to do exactly this function in python?