Returns a list of indices in the order as when the given list is sorted. For example: ["c","a","b"] => [1, 2, 0] This means that in the sorted list, "a" (index 1) comes first and "c" (index 0) last.
(list, cmp=None, key=None, reverse=False)
| 317 | #### LIST FUNCTIONS ################################################################################ |
| 318 | |
| 319 | def order(list, cmp=None, key=None, reverse=False): |
| 320 | """ Returns a list of indices in the order as when the given list is sorted. |
| 321 | For example: ["c","a","b"] => [1, 2, 0] |
| 322 | This means that in the sorted list, "a" (index 1) comes first and "c" (index 0) last. |
| 323 | """ |
| 324 | if cmp and key: |
| 325 | f = lambda i, j: cmp(key(list[i]), key(list[j])) |
| 326 | elif cmp: |
| 327 | f = lambda i, j: cmp(list[i], list[j]) |
| 328 | elif key: |
| 329 | f = lambda i, j: int(key(list[i]) >= key(list[j])) * 2 - 1 |
| 330 | else: |
| 331 | f = lambda i, j: int(list[i] >= list[j]) * 2 - 1 |
| 332 | return sorted(range(len(list)), cmp=f, reverse=reverse) |
| 333 | |
| 334 | _order = order |
| 335 |