OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 """Intelligent natural sort implementation.""" | 5 """Intelligent natural sort implementation.""" |
6 | 6 |
7 import re | 7 import re |
8 | 8 |
9 | 9 |
10 def natcmp(a, b): | 10 def natcmp(a, b): |
11 """Natural string comparison, case sensitive.""" | 11 """Natural string comparison, case sensitive.""" |
12 try_int = lambda s: int(s) if s.isdigit() else s | 12 try_int = lambda s: int(s) if s.isdigit() else s |
13 def natsort_key(s): | 13 def natsort_key(s): |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 >>> natsorted(['3A2', '3a1'], cmp=naticasecmp) | 65 >>> natsorted(['3A2', '3a1'], cmp=naticasecmp) |
66 ['3a1', '3A2'] | 66 ['3a1', '3A2'] |
67 >>> natsorted(['3a2', '3A1'], cmp=naticasecmp) | 67 >>> natsorted(['3a2', '3A1'], cmp=naticasecmp) |
68 ['3A1', '3a2'] | 68 ['3A1', '3a2'] |
69 >>> natsorted(['3A2', '3a1']) | 69 >>> natsorted(['3A2', '3a1']) |
70 ['3A2', '3a1'] | 70 ['3A2', '3a1'] |
71 >>> natsorted(['3a2', '3A1']) | 71 >>> natsorted(['3a2', '3A1']) |
72 ['3A1', '3a2'] | 72 ['3A1', '3a2'] |
73 """ | 73 """ |
74 return sorted(seq, cmp=cmp, *args, **kwargs) | 74 return sorted(seq, cmp=cmp, *args, **kwargs) |
OLD | NEW |