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
return bin(lo, mid - 1) if -1 ==
bin(mid + 1, hi) if 1 ==
mid
)
Line 3,954:
if __name__ == '__main__':
main()</lang>
{{Out}}
<pre>Word found at index 9
Word of given length found at index 10</pre>
===Python: Library===
|