How can I approach this problem?
Write a program to print the following, Given a word W and pattern P, you need to check whether the pattern matches the given word. The word will only contain letters(can be Uppercase and Lowercase). The pattern can contain letters, ? and *.
? : Can be matched with any single letter. * : Can be matched with any sequence of letters (including an empty sequence).
If the pattern matches with the given word, print True else False.
Sample Input1
3
Hello *l?
Hell He?ll
Hell ?*
Sample Output1
True
False
True
Sample Input2
3
Hello Hell*
Hell He*ll
Hell hell*
Sample Output2
True
True
False
def get(b):
lis=""
char=""
m,k=b
for i in k:
if i in m:
lis+=i
else:
if (i=="*") or (i=="?"):
char+=i
if lis in m:
return True
elif lis.startswith("*") and lis in m:
return True
elif len(lis)==0 and char in ("*","?"):
return True
n=int(input())
for i in range(n):
b=input().split()
res=get(b)
print(res)