1

I am trying to write a query that can return me the list items if they contain words from other list.

Words = [ ‘fuel’ , ‘regular’ , ‘clause’ , ‘maximum’ ]

KP = [ ‘ fuel surcharge policy ‘ , ‘Rsp’ , ‘ liability clause’ , ‘Volume’ ] 

Output = [ ‘ fuel surcharge‘  , liability clause’ ]

The above output am expecting because it contains ‘fuel’ and ‘clause’ from the first list.

Am using the code below, but am getting NA as output.

Output = []
for i,j in zip (Words, KP):
        if i in j:
            Output.append (j)
        else:
            print ('NA")
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61

1 Answers1

0

You can try:

Words = [ "fuel" , "regular" , "clause" , "maximum" ]
       
KP = [ "fuel surcharge policy " , "Rsp" , "liability clause" , "Volume" ]

output=[]
for data in KP:
    for word in data.split():
        if word in Words:
            output.append(data)

print(output)
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61