From 148d05c8bf4f5a7c0fa5075946b350c524e8b43e Mon Sep 17 00:00:00 2001 From: xzg Date: Tue, 12 Dec 2017 23:34:44 +0800 Subject: [PATCH] Add sort for string and test case --- pydu/string.py | 11 +++++++++++ tests/test_string.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pydu/string.py b/pydu/string.py index cdd541f..7ff0f08 100644 --- a/pydu/string.py +++ b/pydu/string.py @@ -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 + + + diff --git a/tests/test_string.py b/tests/test_string.py index 6715995..f25b4dd 100644 --- a/tests/test_string.py +++ b/tests/test_string.py @@ -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' + + + + +