Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
binary_search_in_python
def binary_search(list,term): #print(len(list)) if len(list) == 0: return "Not found" mid = int(list.__len__()/2) if(list[mid] == term): return list[mid] if(term > list[mid]): last = -1 if mid == 1 else len(list) return binary_search(list[mid:last],term) else: return binary_search(list[0:mid],term) def binary_search_while(list,term): while len(list) != 0: mid = int(len(list)/2) if list[mid] == term: return list[mid] if(term > list[mid]): last = -1 if mid == 1 else len(list) list = list[mid:last] else: list = list[0:mid] return "not found" list = [1,2,3,4,5,6,7,8] print(binary_search_while(list,9))
run
|
edit
|
history
|
help
0
dict()
fibo_1
Calc1
Variables.py
PyDIP
Range List for Python
9th jan1
ggh
Sieve of Eratosthenes
Python mehrfachvererbung