[Python] 遍歷資料夾
〇 os.scandir() os.scandir(path='.') -> iterator of os.DirEntry objects 回傳path底下的檔案與子資料夾構成的os.DirEntry物件 (object) 的iterator 效率顯著地比os.listdir()好 △ os.listdir() os.listdir(path='.') -> list 回傳path底 ...
〇 os.scandir() os.scandir(path='.') -> iterator of os.DirEntry objects 回傳path底下的檔案與子資料夾構成的os.DirEntry物件 (object) 的iterator 效率顯著地比os.listdir()好 △ os.listdir() os.listdir(path='.') -> list 回傳path底 ...
import functools def catch_exception(func): @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: print 'Caught an exception in', f.__name__ ret ...
安裝 安裝 MongoDB MongoDB手冊: 安裝 MongoDB 安裝 pymongo Python Package Index: pymongo 安裝 MongoDB for VS Code Visual Studio Code: Working with MongoDB MongoDB: MongoDB for VS Code 資料庫結構 資料庫結構 (大 → 小) MySQL data ...
pip install requests GET / POST response = requests.get(url) response = requests.post(url) Response JSON response.json()
assert expression[, arguments] ≡ if not expression: raise AssertionError[(arguments)]
單行 <span style="color: #CF4D72; background-color: #f7f7f7; border: 1px #DEDEDE solid;"> ... </span> 多行 <div style="color: #CF4D72; background-color: #f7f7f7; border: 1px #DEDEDE s ...
asyncio: Library for writing concurrent code. async / await 3.5 版前async def函數內無法使用yield或 yield from 會引發SyntaxError錯誤 3.6 版以後有了 Asynchronous Generators 而可以使用yield 使用例 import asyncio import time ...
Problem https://leetcode.com/problems/target-sum First Try [Time Limit Exceeded 124 / 140 testcases passed] Time Complexity: O(2 ** len(nums)) Space Complexity: O(2 ** len(nums)) (The input and outpu ...
Problem https://leetcode.com/problems/find-largest-value-in-each-tree-row Solution: BFS Time Complexity: O(len(tree)) Space Complexity: O(log(len(tree))) (The input and output generally do not count t ...
Problem https://leetcode.com/problems/find-building-where-alice-and-bob-can-meet Given a, b If a == b, let k = a = b If heights[max(a, b)] > heights[min(a, b)] ⇒ ans = max(a, b) K = set([k for k in ...