From 941d1d4b5cb7e5ed57f85997c41cc4c1a6f615d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Mon, 17 Jan 2022 15:42:26 +0100 Subject: [PATCH 1/1] Create test.py --- test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..ef671a7 --- /dev/null +++ b/test.py @@ -0,0 +1,18 @@ + +def binary_search(key: int, srt_list: list, carry=0): + length = len(srt_list) + idx = length // 2 + + if key > srt_list[idx]: + return binary_search(key, srt_list[idx:], carry=carry+idx) + elif key < srt_list[idx]: + return binary_search(key, srt_list[:idx], carry=carry) + else: + return carry + idx + + +if __name__ == "__main__": + myList = [12, 45, 345, 345, 234, 13, 1, 5] + myList.sort() + print(myList) + print(binary_search(345, myList)) -- 2.30.2