You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73-37Lines changed: 73 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,12 +36,12 @@ cmp_func|Multi column sorting in the model `java.util.Comparator`|Reasonable spe
36
36
superfast|NoneType safe sample implementation of multi column sorting as mentioned in [example from python docs](https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts)|Fastest by orders of magnitude but a bit more complex to write.
Sort rows_dict by _grade_, descending, then _attend_, ascending and put None first in results:
55
+
Sort rows_before by _grade_, descending, then _attend_, ascending and put None first in results:
56
+
```
57
+
from multisort import multisort, mscol
58
+
rows_sorted = multisort(rows_before, [
59
+
mscol('grade', reverse=False),
60
+
'attend'
61
+
])
62
+
```
63
+
64
+
-or- without `mscol`
65
+
56
66
```
57
67
from multisort import multisort
58
-
rows_sorted = multisort(rows_dict, [
59
-
('grade', reverse=False),
60
-
('attend')
68
+
rows_sorted = multisort(rows_before, [
69
+
('grade', False),
70
+
'attend'
61
71
])
72
+
```
62
73
74
+
Sort rows_before by _grade_, descending, then _attend_ and call upper() for _grade_:
63
75
```
64
-
Sort rows_dict by _grade_, descending, then _attend_ and call upper() for _grade_:
76
+
from multisort import multisort, mscol
77
+
rows_sorted = multisort(rows_before, [
78
+
mscol('grade', reverse=False, clean=lambda s: None if s is None else s.upper()),
79
+
'attend'
80
+
])
81
+
```
82
+
83
+
-or- without `mscol`
65
84
```
66
85
from multisort import multisort
67
-
rows_sorted = multisort(rows_dict, [
68
-
mscol('grade', 'reverse'=False, clean=lambda s: None if s is None else s.upper()),
69
-
('attend')
86
+
rows_sorted = multisort(rows_before, [
87
+
('grade', False, lambda s: None if s is None else s.upper()),
88
+
'attend'
70
89
])
71
-
72
90
```
91
+
92
+
73
93
`multisort` parameters:
74
94
option|dtype|description
75
95
---|---|---
76
96
`rows`|int or str|Key to access data. int for tuple or list
77
97
`spec`|str, int, list|Sort specification. Can be as simple as a column key / index or `mscol`
78
98
`reverse`|bool|Reverse order of final sort (defalt = False)
79
99
80
-
`multisort` spec options:
81
-
option|dtype|description
82
-
---|---|---
83
-
`key`|int or str|Key to access data. int for tuple or list
84
-
`reverse`|bool|Reverse sort of column
85
-
`clean`|func|Function / lambda to clean the value. These calls can cause a significant slowdown.
86
-
`required`|bool|Default True. If false, will substitute None or default if key not found (not applicable for list or tuple rows)
87
-
`default`|any|Value to substitute if required==False and key does not exist or None is found. Can be used to achive similar functionality to pandas `na_position`
100
+
101
+
`spec` entry options:
102
+
option|position|dtype|description
103
+
---|---|---|---
104
+
`key`|0|int or str|Key to access data. int for tuple or list
105
+
`reverse`|1|bool|Reverse sort of column
106
+
`clean`|2|func|Function / lambda to clean the value. These calls can cause a significant slowdown.
107
+
`required`|3|bool|Default True. If false, will substitute None or default if key not found (not applicable for list or tuple rows)
108
+
`default`|4|any|Value to substitute if required==False and key does not exist or None is found. Can be used to achive similar functionality to pandas `na_position`
109
+
110
+
\*`spec` entries can be passed as:
111
+
type|description
112
+
---|---
113
+
`String`|Column name
114
+
`tuple`|Tuple of 1 or more `spec` options in their order as listed (see `position`)
115
+
`mscol()`|Importable helper to aid in readability. Suggested for three or more of the options.
116
+
117
+
118
+
<br><br>
88
119
89
120
90
121
### `sorted` with `cmp_func`
91
-
Sort rows_dict by _grade_, descending, then _attend_ and call upper() for _grade_:
122
+
Sort rows_before by _grade_, descending, then _attend_ and call upper() for _grade_:
0 commit comments