MCPcopy
hub / github.com/celery/celery / sample

Function sample

celery/utils/debug.py:102–116  ·  view source on GitHub ↗

Given a list `x` a sample of length ``n`` of that list is returned. For example, if `n` is 10, and `x` has 100 items, a list of every tenth. item is returned. ``k`` can be used as offset.

(x, n, k=0)

Source from the content-addressed store, hash-verified

100
101
102def sample(x, n, k=0):
103 """Given a list `x` a sample of length ``n`` of that list is returned.
104
105 For example, if `n` is 10, and `x` has 100 items, a list of every tenth.
106 item is returned.
107
108 ``k`` can be used as offset.
109 """
110 j = len(x) // n
111 for _ in range(n):
112 try:
113 yield x[k]
114 except IndexError:
115 break
116 k += j
117
118
119def hfloat(f, p=5):

Callers 1

_memdumpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected