Jump to content

Binary search: Difference between revisions

→‎Python: Recursive: Adjusted one bound name to avoid shadowing. Added output.
(→‎Python: Recursive: Added a version generalising binary sort from direct matches to the use of custom comparator functions.)
(→‎Python: Recursive: Adjusted one bound name to avoid shadowing. Added output.)
Line 3,890:
else:
mid = (lo + hi) // 2
cmpcmpr = p(xs[mid])
return bin(lo, mid - 1) if -1 == cmpcmpr else (
bin(mid + 1, hi) if 1 == cmpcmpr else (
mid
)
Line 3,954:
if __name__ == '__main__':
main()</lang>
{{Out}}
<pre>Word found at index 9
<pre></pre>
Word of given length found at index 10</pre>
 
===Python: Library===
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.