Sha256: 9584a6463d2a3db14d57d94d48b82b67dd75b1de2862f3416dc815268b02e989

Contents?: true

Size: 363 Bytes

Versions: 396

Compression:

Stored size: 363 Bytes

Contents

def binary_search(search_list, value):
    low = 0
    high = len(search_list) - 1
    while low <= high:
        middle = (low + high) // 2
        if search_list[middle] > value:
            high = middle - 1
        elif search_list[middle] < value:
            low = middle + 1
        else:
            return middle
    raise ValueError("Value not found.")

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.179 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.178 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.177 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.176 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.175 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.174 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.173 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.172 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.171 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.170 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.169 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.167 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.166 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.165 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.164 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.163 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.162 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.161 tracks/python/exercises/binary-search/example.py
trackler-2.2.1.160 tracks/python/exercises/binary-search/example.py