MCPcopy Index your code
hub / github.com/clips/pattern / order

Function order

pattern/db/__init__.py:319–332  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

317#### LIST FUNCTIONS ################################################################################
318
319def 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

Callers 1

sortMethod · 0.85

Calls 2

cmpFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…