經典電腦科學問題解析:使用Python - 第一章 - 閱讀筆記
Classic Computer Science Problems in Python
經典電腦科學問題解析:使用Python
閱讀補充筆記
第一章:Small problems熱身的小問題
1.1 The Fibonacci sequence
在此介紹了費式數列,除了第一和第二個數字為0及1外,每個數都是前兩數的和。
1.1.3 Memoization to the rescue
在程式碼中運用到了from typing import Dict,typing 是Python 3.5後才新增的模組,為了在自訂函數中增加可讀性。
- 使用 Python typing 模組對你的同事好一點
- https://myapollo.com.tw/zh-tw/python-typing-module/
1.1.4 Automatic memoization
為了減少記憶體空間,使用了LRU演算法,以from functools import lru_cache實現。
- Python - lru_cache和singledispatch装饰器
- https://zhuanlan.zhihu.com/p/27643991/
- 如何使用 Python 實現 LRU Cache 快取置換機制
- https://blog.techbridge.cc/2019/04/06/how-to-use-python-implement-least-recently-used/
1.1.6 Generating Fibonacci numbers with a generator
不透過額外的for迴圈方便將迴圈的運算過程列印出來,使用yield 完成。
- Python 裡的 yield — 讓你簡單、快速瞭解 yield 的概念
- https://chriskang028.medium.com/python-裡的-yield-讓你簡單-快速瞭解-yield-的概念-f660521f3aa7/
留言
張貼留言