Solved! Go to Solution.
d = {'TJMaxx': ['TJ Maxx', 'TJ Max', 'TJX', 'TJMaxx']} SearchTerm = 'TJ Maxx' selected = None # iterate through dictionary, seeing if term in sub list for k in d: if SearchTerm in d: selected = k if selected is not None: ## do something else: ## report invalid entry
d = {'TJMaxx': ['TJ Maxx', 'TJ Max', 'TJX', 'TJMaxx']} # make lists of value, key pairs as items in separate lists l = [[],[]] for k in d: for i in d: l[0].append(i) l[1].append(k) SearchTerm = 'TJ Maxx' # search for item in list, return 'key' value if SearchTerm in l[0]: selected = l[1][l[0].index(SearchTerm)] ## do something else: ## report invalid entry
d = {'TJMaxx': ['TJ Maxx', 'TJ Max', 'TJX', 'TJMaxx']} SearchTerm = 'TJ Maxx' selected = None # iterate through dictionary, seeing if term in sub list for k in d: if SearchTerm in d: selected = k if selected is not None: ## do something else: ## report invalid entry
d = {'TJMaxx': ['TJ Maxx', 'TJ Max', 'TJX', 'TJMaxx']} # make lists of value, key pairs as items in separate lists l = [[],[]] for k in d: for i in d: l[0].append(i) l[1].append(k) SearchTerm = 'TJ Maxx' # search for item in list, return 'key' value if SearchTerm in l[0]: selected = l[1][l[0].index(SearchTerm)] ## do something else: ## report invalid entry
Something like this should do what you want:d = {'TJMaxx': ['TJ Maxx', 'TJ Max', 'TJX', 'TJMaxx']} SearchTerm = 'TJ Maxx' selected = None # iterate through dictionary, seeing if term in sub list for k in d: if SearchTerm in d: selected = k if selected is not None: ## do something else: ## report invalid entry