Tutti Nuovi

user:thomas utente che ha creato il gist

title:mygist titolo del gist

filename:myfile.txt nome di file nel gist

extension:yml estensione del file nel gist

language:go linguaggio del file nel gist

topic:homelab gists with given topic

Entra


Tutti Nuovi Entra

All gists matching topic python

Più recente creazione
Meno recente creazione
Più recente aggiornamento
Meno recente aggiornamento

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

0 mi piace
0 forks
1 files
Ultima volta attivo 1 year 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 mi piace
0 forks
1 files
Ultima volta attivo 1 year 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() # 呼叫函式
Più nuovi Più vecchi

Creato da Opengist ⋅ Load: 48ms⋅

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