All New

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Login


All New Login

All gists matching topic python

Recently created
Least recently created
Recently updated
Least recently updated

timmy / 使用 funcy.flatten 展平巢狀列表

0 likes
0 forks
1 files
Last active 10 months ago
此程式使用 funcy.flatten 函式,將多層巢狀列表展平成單一列表,適用於數據處理與資料結構轉換,提高數據操作的便利性。
data-processing flatten funcy list python transformation utilities
1 from funcy import flatten # 匯入 funcy 模組中的 flatten 函式
2
3 mylist = [[1, 2, 3], [2, 3, 4], [3, 4, 5]] # 定義一個包含多個子列表的列表
4
5 print(list(flatten(mylist))) # 將 mylist 中的多個子列表展平後轉換成列表並印出

timmy / 使用 funcy 裝飾器測量函式執行時間

0 likes
0 forks
1 files
Last active 10 months ago
這段程式碼使用 funcy 模組的 print_durations 裝飾器,測量並印出 func 函式的執行時間,範例中透過簡單的迴圈模擬運算過程。
benchmarking decorator funcy performance profiling python timing
1 from funcy import print_durations # 匯入 funcy 模組中的 print_durations 裝飾器
2
3 @print_durations # 裝飾器:用於計算函式執行時間並印出
4 def func():
5 """一個範例函式,使用範例裝飾器 print_durations 來印出其執行時間。"""
6 for i in range(10000): # 進行一個範例的迴圈計算
7 pass
8
9 func() # 呼叫函式
Newer Older

Powered by Opengist ⋅ Load: 59ms⋅

English
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文