Iterate over the dictionary and use the in
operator to see if each phrase is in the input. If it is, use the index
method to find out where so that you can sort the results by that index. Then you can remove the index from the final result so you just have tuples of the ids and values.
>>> user_input = 'hello and good evening. how are you. im bored and need some entertainment. please tell me a joke.'
>>> data = {
... 3: 'hello',
... 24: 'tell me a joke',
... 34: 'im bored',
... 42: 'what time is it',
... 56: 'how are you',
... 69: 'what are you doing',
... }
>>>
>>> [(k, v) for _, k, v in sorted(
... (user_input.index(v), k, v)
... for k, v in data.items()
... if v in user_input
... )]
[(3, 'hello'), (56, 'how are you'), (34, 'im bored'), (24, 'tell me a joke')]
Or, since you already have the database that tells you the string for each id, you could just compute the list of ids like this:
>>> [k for _, k in sorted(
... (user_input.index(v), k)
... for k, v in data.items()
... if v in user_input
... )]
[3, 56, 34, 24]
and then of course you can take that list and do things like:
>>> " ".join(data[i] for i in [3, 56, 34, 24])
'hello how are you im bored tell me a joke'
etc