python - How to match strings even if only they match partially? -
i have 2 lists i'd compare , if there match (even if partial) carry out action. i've set 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 key in keywords): print 'ok'
as can see, there partial match between 1st item of keywords
, 2nd , 3rd item of metakeywords
, should print ok
. how can this? thanks!
dani
if want find out if item in keywords
contained in item in metakeywords
, can this:
if any(key in metakey key in keywords metakey in metakeywords): print 'ok'
Comments
Post a Comment