作者peter308 (pete)
看板Python
標題[問題] 怎麼把list裡面的方括號去除掉?
時間Tue May 30 22:32:25 2023
假設我有一個list
L = [[1],[2],[3],[4],[5,6,7,8]]
怎麼下指令 讓
L = [1,2,3,4,5,6,7,8]
把 L 裡面的 中括號 全部去除掉
感謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.204.239.10 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1685457148.A.E98.html
2F:→ lycantrope: 沒版主,來洗文章。2012洗到現在還在問這種問題 05/30 23:20
3F:→ peter308: 感謝1F m(_ _)m 05/30 23:42
4F:→ leolarrel: 認同二樓 05/31 10:52
5F:→ joshddd: aa = [[1], [2], [3, 4]] 05/31 18:12
6F:→ joshddd: from functools import reduce 05/31 18:12
7F:→ joshddd: reduce(lambda x, y: x + y, aa) 05/31 18:12
8F:→ peter308: 感謝Josh大! 06/02 11:14
9F:→ peter308: 學習到新指令! 06/02 11:14
10F:→ kobenein: list(chain(*L)) 06/03 14:02
11F:推 poototo: sum(L, start=[]) 06/04 00:19
12F:推 pmove: 推11漏 06/14 15:56
13F:→ pmove: 樓 06/14 15:56