Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 29ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

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

all:systemctl search all fields

Login
t

transformation

Recently created Least recently created Recently updated Least recently updated

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

Last active 6 hours ago data-processing flatten funcy list python transformation utilities

此程式使用 funcy.flatten 函式,將多層巢狀列表展平成單一列表,適用於數據處理與資料結構轉換,提高數據操作的便利性。

0 0 0 1
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 中的多個子列表展平後轉換成列表並印出