MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / find_closest

Function find_closest

example_code/item_102.py:57–61  ·  view source on GitHub ↗
(sequence, goal)

Source from the content-addressed store, hash-verified

55
56print("Example 2")
57def find_closest(sequence, goal):
58 for index, value in enumerate(sequence):
59 if goal < value:
60 return index
61 raise ValueError(f"{goal} is out of bounds")
62
63index = find_closest(data, 91234.56)
64assert index == 91235

Callers 1

item_102.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected