Re: [問題] list中的list

看板Python作者 (dschen)時間6年前 (2018/09/12 22:56), 編輯推噓0(001)
留言1則, 1人參與, 6年前最新討論串3/4 (看更多)
※ 引述《tommy5617 (地瓜YA!)》之銘言: : 各位大大好 : 新手初次提問還請多多指教 : 想請問關於list中還有list的問題 : list1 = [ [1,2], [3,4,5], [6], [7,8,9,10] ] : 1.我想把裡面的list依照他們的元素多寡重新排序: : list2 = [ [7,8,9,10], [3,4,5], [1,2], [6] ] : 2.我想把裡面的list拆開: : list3 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] : 先謝謝了 剛好最近用到,可參考 list2 = sorted(list1, key=lambda x: len(x), reverse=True) from functools import reduce list3 = reduce(lambda e1, e2: e1 + e2, list1) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.238.88.227 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1536764205.A.60D.html

09/13 00:06, 6年前 , 1F
謝謝:)
09/13 00:06, 1F
文章代碼(AID): #1RcIajOD (Python)
討論串 (同標題文章)
文章代碼(AID): #1RcIajOD (Python)