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
  • 19,194
  • 5
  • 54
  • 65
Mansi Dhingra
  • 39
  • 1
  • 9

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
Red
  • 26,798
  • 7
  • 36
  • 58