I have a list of keywords including their variations that I search in text like :
keywords = ['US Dollar', 'Australian Dollar', 'Dollar', 'Dollars']
and I want to look up these keywords in texts like :
'Dollar News: The Australian Dollar slumped in the face of a recovering US Dollar'
and get the most comprhensive matches (i.e. longest) which are 'Dollar' in the beginning of the sentence, and 'Australian Dollar' and 'US Dollar'(and not 'Dollar' in those cases for instance).
I have so far tried this:
keywords.sort(key = len, reverse=True)
first = lambda text, kws: next((k for k in kws if k in text), None)
first(myText, keywords)
which returns 'Australian Dollar' as it is the longest match. How can I get other matches (here, 'Dollar' in 'Dollar News...' and 'US Dollar') as well?