GitHub 热门:Python 算法大全,Star 超过 2 万


Posted in Python onApril 29, 2019

4 月 27 日,GitHub 趋势榜第 3 位是一个用 Python 编码实现的算法库,Star 数早已达到 26000+

GitHub 热门:Python 算法大全,Star 超过 2 万

链接:https://github.com/TheAlgorithms/Python

这个库涵盖了多种算法和数据结构的介绍,比如:

  • 排序算法(冒泡排序、希尔排序、插入排序、桶排序、合并排序、快速排序、堆排序、选择排序等)、
  • 查找算法(线性查找、二分查找、插值查找等)
  • 加密算法(凯撒加密、RSA、ROT13 等)
  • 机器学习
  • 数字图像处理
  • 动态规划
  • 常见数据结构(队列、栈、链表、树等)

GitHub 热门:Python 算法大全,Star 超过 2 万

这个库虽然包括的种类很多,但内容其实分了 2 方面:① 算法的原理简介;② 算法的代码实现;

比如:冒泡算法的 Python 实现

from __future__ import print_function
def bubble_sort(collection):
  """Pure implementation of bubble sort algorithm in Python
  :param collection: some mutable ordered collection with heterogeneous
  comparable items inside
  :return: the same collection ordered by ascending
  Examples:
  >>> bubble_sort([0, 5, 3, 2, 2])
  [0, 2, 2, 3, 5]
  >>> bubble_sort([])
  []
  >>> bubble_sort([-2, -5, -45])
  [-45, -5, -2]
  >>> bubble_sort([-23,0,6,-4,34])
  [-23,-4,0,6,34]
  """
  length = len(collection)
  for i in range(length-1):
    swapped = False
    for j in range(length-1-i):
      if collection[j] > collection[j+1]:
        swapped = True
        collection[j], collection[j+1] = collection[j+1], collection[j]
    if not swapped: break # Stop iteration if the collection is sorted.
  return collection
if __name__ == '__main__':
  try:
    raw_input     # Python 2
  except NameError:
    raw_input = input # Python 3
  user_input = raw_input('Enter numbers separated by a comma:').strip()
  unsorted = [int(item) for item in user_input.split(',')]
  print(*bubble_sort(unsorted), sep=',')

感兴趣的童鞋,请收藏:

https://github.com/TheAlgorithms/Python

好了,就给大家介绍到这里吧,希望大家喜欢!

Python 相关文章推荐
python进程管理工具supervisor使用实例
Sep 17 Python
pandas全表查询定位某个值所在行列的方法
Apr 12 Python
Matplotlib 生成不同大小的subplots实例
May 25 Python
python中协程实现TCP连接的实例分析
Oct 14 Python
Python中py文件转换成exe可执行文件的方法
Jun 14 Python
python 缺失值处理的方法(Imputation)
Jul 02 Python
Python中的上下文管理器相关知识详解
Sep 19 Python
简单了解python字符串前面加r,u的含义
Dec 26 Python
Python实现读取并写入Excel文件过程解析
May 27 Python
浅析Python requests 模块
Oct 09 Python
python自动统计zabbix系统监控覆盖率的示例代码
Apr 03 Python
详解PyTorch模型保存与加载
Apr 28 Python
python实现nao机器人手臂动作控制
Apr 29 #Python
python机器人运动范围问题的解答
Apr 29 #Python
浅谈Python3中strip()、lstrip()、rstrip()用法详解
Apr 29 #Python
Python 实现微信防撤回功能
Apr 29 #Python
python程序控制NAO机器人行走
Apr 29 #Python
Django web框架使用url path name详解
Apr 29 #Python
Python对HTML转义字符进行反转义的实现方法
Apr 28 #Python
You might like
骨王战斗力在公会成员中排不进前五,却当选了会长,原因竟是这样
2020/03/02 日漫
打造超酷的PHP数据饼图效果实现代码
2011/11/23 PHP
CentOS 6.2使用yum安装LAMP以及phpMyadmin详解
2013/06/17 PHP
php单态设计模式(单例模式)实例
2014/11/18 PHP
ThinkPHP控制器里javascript代码不能执行的解决方法
2014/11/22 PHP
php中执行系统命令的方法
2015/03/21 PHP
Smarty模板引擎缓存机制详解
2016/05/23 PHP
PHP安装BCMath扩展的方法
2019/02/13 PHP
PHP设计模式之简单工厂和工厂模式实例分析
2019/03/25 PHP
实现laravel 插入操作日志到数据库的方法
2019/10/11 PHP
php设计模式之抽象工厂模式分析【星际争霸游戏案例】
2020/01/23 PHP
jquery操作HTML5 的data-*的用法实例分享
2014/08/17 Javascript
jquery实现华丽的可折角广告代码
2015/09/02 Javascript
jQuery插件编写步骤详解
2016/06/03 Javascript
vue.js开发环境搭建教程
2017/05/04 Javascript
vue 项目打包通过命令修改 vue-router 模式 修改 API 接口前缀
2018/06/13 Javascript
Node.js 进程平滑离场剖析小结
2019/01/24 Javascript
详解关于element级联选择器数据回显问题
2019/02/20 Javascript
[02:12]打造更好的电竞完美世界:完美盛典回顾篇
2018/12/19 DOTA
python远程登录代码
2008/04/29 Python
Django生成PDF文档显示在网页上以及解决PDF中文显示乱码的问题
2019/07/04 Python
简单了解python变量的作用域
2019/07/30 Python
PyCharm下载和安装详细步骤
2019/12/17 Python
PyQt5 界面显示无响应的实现
2020/03/26 Python
HTML5 新标签全部总汇(推荐)
2016/06/13 HTML / CSS
Glamest意大利:女性在线奢侈品零售店
2019/04/28 全球购物
FORZIERI福喜利中国官网:奢侈品购物梦工厂
2019/05/03 全球购物
汽车运用工程专业毕业生推荐信
2013/12/25 职场文书
如何写一份好的英文求职信
2014/03/19 职场文书
弘扬职业精神演讲稿
2014/03/20 职场文书
经理岗位职责范本
2015/04/15 职场文书
2016大学军训心得体会
2016/01/11 职场文书
2016学校先进集体事迹材料
2016/02/29 职场文书
mysql sum(if())和count(if())的用法说明
2022/01/18 MySQL
Tomcat用户管理的优化配置详解
2022/03/31 Servers
SQLServer常见数学函数梳理总结
2022/08/05 MySQL