看板 Python 關於我們 聯絡資訊
各位大大好 新手初次提問還請多多指教 想請問關於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] 先謝謝了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.107.90 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1536761679.A.0FD.html
ThxThx: 請愛用內建library 09/12 22:52
ThxThx: from itertools import chain 09/12 22:52
ThxThx: list(chain.from_iterables(list3)) 09/12 22:52
ThxThx: 更正:list2 09/12 22:52
me356500: Numpy? 09/12 23:08
TitanEric: 感覺可以用個sort(list, key=Len(sub list))之類的排序 09/12 23:35
tommy5617: 謝謝大家!原來用sorted排序就可以了 09/13 00:06
sean50301: sorted(list1,key=lambda l:len(l)) 09/13 19:04
sean50301: sorted(list1,key=len) 09/13 19:05