摘要:
Python 线性查找 线性查找指按一定的顺序检查数组中每一个元素,直到找到所要寻找的特定值为止。 def line_search(arr, n, x): for i in range(0, n): if arr[i] == x: return i return -1 arr=['a','b','c 阅读全文
摘要:
Python 二分查找 二分搜索是一种在有序数组中查找某一特定元素的搜索算法。搜索过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜索过程结束;如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。如果在某一步骤数组为空,则代表 阅读全文
摘要:
方法1: (参考https://suixinblog.cn/2019/01/print-colorful.html) 使用Python中自带的print输出带有颜色或者背景的字符串 书写语法 print(\033[显示方式;前景色;背景色m输出内容\033[0m)其中,显示方式、前景色、背景色都是可 阅读全文
摘要:
def customer(): r="" while True: n=yield r#,接收生产者的消息,并向消费者发送r print("customer receive",n) r="ok" def produce(c): c.send(None)#第一次启动协程必须发送None值,否则报如下错误 阅读全文
摘要:
安装 pip install gevent import gevent from gevent import monkey monkey.patch_all()#捕捉所有阻塞,不止接收gevent.sleep import time def f(s): print("hello %s"%s) tim 阅读全文