前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >气象编程 | 常见算法的Python实现(Github标星7.6W+)

气象编程 | 常见算法的Python实现(Github标星7.6W+)

作者头像
气象学家
发布2020-06-21 11:32:36
8460
发布2020-06-21 11:32:36
举报
文章被收录于专栏:气象学家气象学家

我找到一个github标星75.5k+star的仓库,把各种常见算法用python实现了,而且还有动图演示,非常值得推荐。(黄海广)

仓库说明

这个仓库用python语言实现了绝大部分算法,主要是用于教学目的,因此效率稍微低于工业界。

仓库地址:https://github.com/TheAlgorithms/Python

内容说明

包含了常见的算法的python实现,如二叉树、排序、查找等等。这些是算法工程师必须掌握的技能。

文件目录

冒泡排序

桶排序

快速排序

代码语言:javascript
复制
排序典型代码(这个是冒泡排序的代码):
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, 2, 3, 2])
    [0, 2, 2, 3, 5]

    >>> bubble_sort([])
    []

    >>> bubble_sort([-2, -45, -5])
    [-45, -5, -2]

    >>> bubble_sort([-23, 0, 6, -4, 34])
    [-23, -4, 0, 6, 34]

    >>> bubble_sort([-23, 0, 6, -4, 34]) == sorted([-23, 0, 6, -4, 34])
    True
    """
    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__":
    import time

    user_input = input("Enter numbers separated by a comma:").strip()
    unsorted = [int(item) for item in user_input.split(",")]
    start = time.process_time()
    print(*bubble_sort(unsorted), sep=",")
    print(f"Processing time: {time.process_time() - start}")


总结

数据结构与算法设计怎么学?

免费的我推荐严蔚敏老师的数据结构课程,网上可以查到,用c语言实现,当年考博士时候学的就是这个。

收费的我推荐极客时间的《数据结构与算法之美》:http://gk.link/a/108GK ,内容挺全面,学了应该对算法有很大帮助。

算法的python实现推荐github上一个75.5k+star的仓库,把各种常见算法用python实现了,而且还有动图演示。

仓库地址: https://github.com/TheAlgorithms/Python

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-06-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 气象学家 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 仓库说明
  • 内容说明
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档