How to test if none of the iterables are true in Python 3 -
the task take inputted string (query
) , see if of words match keys in dictionary (rsp_dict
). simple.
words = query.split() each in words: if each in rsp_dict: print(rsp_dict[each])
but can't figure out, how make print out phrase if none of words match keys dictionary. i've tried million different methods, end phrase printing every false value, rather once.
i'm hoping learn or guidance appreciated. please feel free suggest edits on how i've phrased question.
you can this:
words = query.split() not_found = true each in words: if each in rsp_dict: print(rsp_dict[each]) not_found = false if not_found: print("the phrase not found!")
hope helps!
Comments
Post a Comment