mirror of https://github.com/flaggo/pydu.git
Add describtion for common preffix and suffix
This commit is contained in:
parent
60e4b1eb05
commit
64e6f2aaca
|
@ -102,6 +102,11 @@ def strips(text, remove):
|
||||||
|
|
||||||
|
|
||||||
def common_prefix(l):
|
def common_prefix(l):
|
||||||
|
"""
|
||||||
|
Return common prefix of the stings
|
||||||
|
>>> common_prefix(['abcd', 'abc1'])
|
||||||
|
'abc'
|
||||||
|
"""
|
||||||
commons = []
|
commons = []
|
||||||
for i in range(min(len(s) for s in l)):
|
for i in range(min(len(s) for s in l)):
|
||||||
common = l[0][i]
|
common = l[0][i]
|
||||||
|
@ -113,6 +118,11 @@ def common_prefix(l):
|
||||||
|
|
||||||
|
|
||||||
def common_suffix(l):
|
def common_suffix(l):
|
||||||
|
"""
|
||||||
|
Return common suffix of the stings
|
||||||
|
>>> common_suffix(['dabc', '1abc'])
|
||||||
|
'abc'
|
||||||
|
"""
|
||||||
commons = []
|
commons = []
|
||||||
for i in range(min(len(s) for s in l)):
|
for i in range(min(len(s) for s in l)):
|
||||||
common = l[0][-i-1]
|
common = l[0][-i-1]
|
||||||
|
@ -121,3 +131,4 @@ def common_suffix(l):
|
||||||
return ''.join(reversed(commons))
|
return ''.join(reversed(commons))
|
||||||
commons.append(common)
|
commons.append(common)
|
||||||
return ''.join(reversed(commons))
|
return ''.join(reversed(commons))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue