0

I am stuck on my python lab from this week. The lab deals with strings and being able to search them, slice them, etc. The part I'm stuck on is as follows:

"You will implement in Python a function matchPat. It will take two arguments, a pattern string and a string, and return a Boolean, which indicates whether or not the pattern matches the initial portion of the string. A wild-card match is represented by an asterisk(*). HINT: You should express the algorithm recursively. Again, a good place to start is nesting the structural pattern. For the wild card, try to translate "zero or more characters" into code. Both logical operators and and or are useful."

So basically, I know where to start and what to do for the code itself, what I am having trouble doing is figuring out how to get the * to match "zero or more characters."

A few quick examples to make the question clear:
>>>matchPat('a*t*r', 'anteaters')
True
>>>matchPat('a*t*r', 'albatross')
True
>>>matchPat('a*t*r', 'artist')
False

This code must be done recursively using if statements and can not include the integrated python function 'in'.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by pyTony
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.