How do I match strings even if they are the same?

I have two lists that I would like to compare, and if there is any match (even if partial) then follow some steps. I installed this test code:

keywords = ['social media','social business','social networking','social marketing','online marketing','social selling',
    'social customer experience management','social cxm','social cem','social crm','google analytics','seo','sem',
    'digital marketing','social media manager','community manager']

metakeywords = ['top 10', 'social media blog', 'social media blog nomination']

if any(key in metakeywords for key in keywords):
    print 'Ok'

      

As you can see, there is a partial match between the 1st item keywords

and the 2nd and 3rd items metakeywords

, so it should print Ok

. How can i do this? Thank!

Dani

+3


source to share


1 answer


If you want to know if any element is contained keywords

in any element in metakeywords

, you can do this:



if any(key in metakey for key in keywords for metakey in metakeywords):
    print 'ok'

      

+7


source







All Articles