{"id":1070,"date":"2023-03-24T09:47:07","date_gmt":"2023-03-24T01:47:07","guid":{"rendered":""},"modified":"2023-03-24T09:47:07","modified_gmt":"2023-03-24T01:47:07","slug":"Python \u5206\u800c\u6cbb\u4e4b","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1070.html","title":{"rendered":"Python \u5206\u800c\u6cbb\u4e4b"},"content":{"rendered":"
\n
Python \u5206\u800c\u6cbb\u4e4b\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n <\/body> <\/p>\n
\u5206\u5272\/\u65ad\u88c2<\/h2>\n
\u89e3\u51b3<\/h2>\n
\u5408\u5e76<\/h2>\n
\u5b9e\u4f8b<\/h3>\n
\u4e8c\u8fdb\u5236\u641c\u7d22\u5b9e\u73b0<\/h2>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-15<\/span>
def <\/span>bsearch(list, val):
list_size = len(list) - 1
idx0 = 0
idxn = list_size
# Find the middle most value
<\/span> while <\/span>idx0 <= idxn:
midval = (idx0 + idxn)\/\/ 2
if <\/span>list[midval] == val:
return <\/span>midval
# Compare the value the middle most value
<\/span> if <\/span>val > list[midval]:
idx0 = midval + 1
else:<\/span>
idxn = midval - 1
if <\/span>idx0 > idxn:
return <\/span>None
# Initialize the sorted list
<\/span> list = [2,7,19,34,53,72]
# print <\/span>the search result
<\/span> print(bsearch(list,72))
print(bsearch(list,11))
<\/span><\/code><\/pre>\n<\/p><\/div>\n5
None
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Python \u5206\u800c\u6cbb\u4e4bzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-1070","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1070"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1070"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1070\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}