Add sort for string and test case

This commit is contained in:
xzg 2017-12-12 23:34:44 +08:00
parent 104b24c010
commit 148d05c8bf
2 changed files with 22 additions and 1 deletions

View File

@ -132,3 +132,14 @@ def common_suffix(l):
commons.append(common)
return ''.join(reversed(commons))
def sort(string, reverse=False):
l = list(string)
l.sort(reverse=reverse)
return "".join(l)
def

View File

@ -1,6 +1,6 @@
# coding: utf-8
from pydu.string import (safeencode, safeunicode, strips, lstrips, rstrips,
common_prefix, common_suffix)
common_prefix, common_suffix,sort)
def test_safeencode():
@ -48,3 +48,13 @@ def test_common_prefix():
def test_common_suffix():
l = ['dabc', '1abc']
assert common_suffix(l) == 'abc'
def test_sort():
assert sort('abc21') == '12abc'
assert sort('abc21',reversed=True) == 'cba21'