Support the author!
Lulu Editions
Paypal Donation
Other Publications
Suppose you come across some code that a previous employee on your project, long moved on and unavailable, wrote. Their code passes unit tests and integration tests, so it probably does the right thing. But they have not given a useful name or documentation for a certain function:
def is_something(s):
return not re.match(r'^(.+?)\1+$', s)
For this puzzle, simply provide a good name and a docstring for this function, to be kind to later programmers.
Before you turn the pageā¦
Code is read far more often than it is written.
This puzzle certainly has many possible answers. For all of them, understanding what the regular expression is doing is the crucial element. The short pattern might look odd, and you need to figure it out. Here is a possibility.
def repeated_prefix(s):
"""Look for any prefix string in 's' and match only if
that prefix is repeated at least once, but it might be
repeated many times. No other substring may occur
between the start and end of the string for a match.
"""
return not re.match(r'^(.+?)\1+$', s)