diff options
-rw-r--r-- | README.rst | 16 | ||||
-rw-r--r-- | natsort/_version.py | 2 | ||||
-rw-r--r-- | natsort/natsort.py | 37 |
3 files changed, 29 insertions, 26 deletions
@@ -45,6 +45,15 @@ Using ``natsort`` is simple:: ``natsort`` identifies the numbers and sorts them separately from letters. +You can also mix and match ``int``, ``float``, ``str``, and ``unicode`` types +when you sort:: + + >>> a = ['4.5', 6, 2.3, u'5'] + >>> sorted(a) + [2.3, 6, '4.5', u'5'] + >>> natsorted(a) + [2.3, '4.5', u'5', 6] + The sorting algorithms '''''''''''''''''''''' @@ -280,6 +289,13 @@ Seth M. Morton History ------- +8-15-2013 v. 3.0.1 +'''''''''''''''''' + + - Added support for unicode strings. + - Removed extraneous ``string2int`` function. + - Fixed empty string removal function. + 7-13-2013 v. 3.0.0 '''''''''''''''''' diff --git a/natsort/_version.py b/natsort/_version.py index 4eb28e3..b7a5531 100644 --- a/natsort/_version.py +++ b/natsort/_version.py @@ -1 +1 @@ -__version__ = '3.0.0' +__version__ = '3.0.1' diff --git a/natsort/natsort.py b/natsort/natsort.py index 4943534..ba9dc3b 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -42,6 +42,12 @@ See the README or the natsort homepage for more details. >>> natsorted(a, number_type=None) ['version-1', 'version-2', 'version-4', 'version-20'] + >>> a = [6, 4.5, '7', u'2.5'] + >>> sorted(a) + [4.5, 6, u'2.5', '7'] + >>> natsorted(a) + [u'2.5', 4.5, 6, '7'] + """ import re @@ -55,26 +61,6 @@ digit_re = re.compile(r'(\d+)') int_re = re.compile(r'([-+]?[0-9]+)') -def string2int(string): - """\ - Convert to integer if an integer string. - - >>> isinstance(string2int('2'), int) - True - >>> isinstance(string2int('a'), str) - True - >>> isinstance(string2int('2.0'), str) - True - - """ - if not isinstance(string, str): - return string - try: - return int(string) - except ValueError: - return string - - def remove_empty(s): """\ Remove empty strings from a list. @@ -84,10 +70,11 @@ def remove_empty(s): ['a', 2, 'b'] """ - try: - s.remove('') - except ValueError: - pass + while True: + try: + s.remove('') + except ValueError: + break return s @@ -209,7 +196,7 @@ def natsort_key(s, number_type=float): """ # If we are dealing with non-strings, return now - if not isinstance(s, str): + if not isinstance(s, basestring): return (s,) # Convert to the proper tuple and return |