+ 2

Do a binary search with for loop in python

23rd Oct 2018, 8:48 AM
Naveen
Naveen - avatar
2 Respuestas
+ 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
23rd Oct 2018, 8:55 AM
Hatsy Rei
Hatsy Rei - avatar
- 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.
23rd Oct 2018, 10:57 AM
Kishalaya Saha
Kishalaya Saha - avatar