Contract Names¶
We wish to contract two given names, both composed of letters (at least one) but they do not necessarily have the same length. We define the string s to be the contraction of strings s1, s2 if and only if:
s1 is a prefix of s
s2 is a sufix of s
it is the sortest (among those the fulfill the two previous conditions)
For instance, 'rosandra' is a contraction of 'rosa' and 'sandra'. But 'mymamamy' is not the contraction of 'myma', 'mamy' (yet it satisfies conditions #1 and #2) since 'mymamy' also does but it is shorter.
You are required to deliver the following function in the module contract (file contract.py):
- contract(n1, n2)¶
such that
For example:
>>> n1, n2 = 'rosa', 'sandra' >>> contract(n1, n2) 'rosandra' >>> n1, n2 = 'myma', 'mamy' >>> contract(n1, n2) 'mymamy' >>> n1, n2 = 'mymay', 'mamy' >>> contract(n1, n2) 'mymaymamy'
Doctests are available in the contract.test file.