
Python基础学习
RunFromHere
AI领域探索
展开
-
Python实现快速排序
Python实现快速排序 关键词:快速 排序 快速排序 算法 比较 基准 python **算法复杂度:**O(nlogn) 代码: def quickSort(array): if len(array) < 2: return array else: pivot = array[0] less = [i for i in array[1:] if i <= pivot] greater = [i for i i原创 2020-12-29 19:59:12 · 278 阅读 · 0 评论 -
Python实现选择排序
Python实现选择排序 关键词:选择排序 排序 算法 寻找 比较 python 实现 **算法复杂度:**O(n^2) 代码: def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] < smallest: smallest = arr[i] smallest_index原创 2020-12-29 19:58:51 · 173 阅读 · 0 评论 -
Python实现二分查找
Python实现二分查找 关键词:算法 查找 基础 复杂度 二分 python 实现 **条件:**带查找的数据需有序 算法复杂度: O(log2(n)) 代码: def binary_search(list, item): low = 0 high = len(list) - 1 while low <= high mid = (low+high)/2 guess = list[mid] if guess == item return mid if gu原创 2020-12-29 19:54:40 · 265 阅读 · 0 评论 -
Python dict 函数
Python dict 函数 关键词:dict() 函数 python 字典 map key value 快速 高效 Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。 用Python写一个dict如下: >>> d = {'Michael': 95, 'Bob': 75, 'Tracy': 85} >>> d['Michael'] 95 为什么dict查找速原创 2020-12-28 13:49:15 · 268 阅读 · 0 评论