[問題] 如何較快從key,value list建立 dict list

看板Python作者 (乾溫)時間5年前 (2019/10/21 16:10), 5年前編輯推噓3(301)
留言4則, 4人參與, 5年前最新討論串1/1
大家好~ 現在有個需求, 當rows多的時候,會變得很慢~ 目前的做法有點慢, 不曉得大家有無比較快的解法? 謝謝~ columns是欄位名稱 rows裡面每個元素都是一個tuple,該tuple個元素其值按位置剛好對應於columns名稱 columns: list of str rows: list of tuple def foo(columns, rows): result = [dict(zip(columns, r)) for r in rows] return result -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.17.41 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1571645407.A.A4D.html ※ 編輯: thanksgive (111.250.17.41 臺灣), 10/21/2019 16:11:12

10/21 17:00, 5年前 , 1F
rows多是多多 慢是多慢?
10/21 17:00, 1F

10/21 18:22, 5年前 , 2F
pandas?
10/21 18:22, 2F

10/21 19:49, 5年前 , 3F
namedtuple 這玩意你有聽過嗎?
10/21 19:49, 3F

10/21 22:04, 5年前 , 4F
pandas感覺超適合
10/21 22:04, 4F
文章代碼(AID): #1ThMVVfD (Python)
文章代碼(AID): #1ThMVVfD (Python)