0

I have a sentence and a list of substrings. How can I check the exact substring occurs in that sentence or not?

For example:

Credit card customers will be allowed interest-free installment plans for all school fee payments as well as grocery purchases with no processing fees for up to six months.

and now I have a list of words

["credit card customers","school fee payment","six months"]. 

How can I check if these substrings exist in above string?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
Mansi Dhingra
  • 29
  • 1
  • 8

1 Answers1

1

Is this what you mean?

string = 'Credit card customers will be allowed interest-free installment plans for all school fee payments as well as grocery purchases with no processing fees for up to six months.'
listing = ["credit card customers","school fee payment","six months"]

def adj_or_not(index1,index2):
    if listing[index1] + listing[index2] in string:
        return True
    else:
        return False

adj_or_not(0,1)

Output:

False
Ann Zen
  • 25,080
  • 7
  • 31
  • 51