更多课程 选择中心


Python培训

400-111-8989

Star 数达到 26000+,这是什么Python算法?

  • 发布:Python培训
  • 来源:Python开发者
  • 时间:2019-04-28 17:34

今天要跟大家介绍的是一个在4 月 27 日,Star 数已达到 26000+,GitHub 趋势榜第 3 位的,用 Python 编码实现的算法库,你有没有兴趣了解一下?

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

排序算法(冒泡排序、希尔排序、插入排序、桶排序、合并排序、快速排序、堆排序、选择排序等)、

查找算法(线性查找、二分查找、插值查找等)

加密算法(凯撒加密、RSA、ROT13 等)

机器学习

数字图像处理

动态规划

常见数据结构(队列、栈、链表、树等)

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

比如:冒泡算法的 Python 实现

冒泡算法的 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=',')

感谢您的阅读,以上就是对Star 数已达到 26000+,GitHub 趋势榜第 3 位的,用 Python 编码实现的算法库,你了解了吗?更多Python相关的内容尽在达内Python培训机构官网,敬请关注!

免责声明:内容和图片源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

预约申请免费试听课

填写下面表单即可预约申请免费试听! 怕学不会?助教全程陪读,随时解惑!担心就业?一地学习,可全国推荐就业!

上一篇:这个Python调试工具,你需要吗?
下一篇:学习Python编程这么久了,你是青铜还是王者?

达内python培训机构就业喜报,用事实告诉你月薪过万不是梦!

python资讯|招聘AI人才开出4000万年薪,真的值吗?

你想自学python语言,因为它是黑客语言?

未来有两种人,会Python的和不懂Python的小学生?

  • 扫码领取资料

    回复关键字:视频资料

    免费领取 达内课程视频学习资料

Copyright © 2023 Tedu.cn All Rights Reserved 京ICP备08000853号-56 京公网安备 11010802029508号 达内时代科技集团有限公司 版权所有

选择城市和中心
黑龙江省

吉林省

河北省

湖南省

贵州省

云南省

广西省

海南省