+ 2
Do a binary search with for loop in python
2 ответов
+ 6
This one is a recursive solution. Please wait while I gather a loop version.
https://www.sololearn.com/learn/705/?ref=app
https://www.sololearn.com/learn/664/?ref=app
Edit: I've found a while loop... Can't seem to find a for version in SL, but it should help you build your version of it.
https://code.sololearn.com/c9ue54NZZOO0/?ref=app
- 1
Due to the rigidity of for loops in Python, it may be a little trickier than it looks. I suppose one could replace the while loop by something like
for _ in range(math.ceil(math.log2(len(my_list))):
But it's not so nice.