Add describtion for common preffix and suffix

This commit is contained in:
xzg 2017-12-11 22:18:30 +08:00
parent 60e4b1eb05
commit 64e6f2aaca
1 changed files with 11 additions and 0 deletions

View File

@ -102,6 +102,11 @@ def strips(text, remove):
def common_prefix(l):
"""
Return common prefix of the stings
>>> common_prefix(['abcd', 'abc1'])
'abc'
"""
commons = []
for i in range(min(len(s) for s in l)):
common = l[0][i]
@ -113,6 +118,11 @@ def common_prefix(l):
def common_suffix(l):
"""
Return common suffix of the stings
>>> common_suffix(['dabc', '1abc'])
'abc'
"""
commons = []
for i in range(min(len(s) for s in l)):
common = l[0][-i-1]
@ -121,3 +131,4 @@ def common_suffix(l):
return ''.join(reversed(commons))
commons.append(common)
return ''.join(reversed(commons))