作者tommy5617 (地瓜YA!)
看板Python
标题[问题] list中的list
时间Wed Sep 12 22:14:37 2018
各位大大好
新手初次提问还请多多指教
想请问关於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://webptt.com/cn.aspx?n=bbs/Python/M.1536761679.A.0FD.html
1F:→ ThxThx: 请爱用内建library 09/12 22:52
2F:→ ThxThx: from itertools import chain 09/12 22:52
3F:→ ThxThx: list(chain.from_iterables(list3)) 09/12 22:52
4F:→ ThxThx: 更正:list2 09/12 22:52
5F:推 me356500: Numpy? 09/12 23:08
6F:推 TitanEric: 感觉可以用个sort(list, key=Len(sub list))之类的排序 09/12 23:35
7F:→ tommy5617: 谢谢大家!原来用sorted排序就可以了 09/13 00:06
8F:推 sean50301: sorted(list1,key=lambda l:len(l)) 09/13 19:04
9F:→ sean50301: sorted(list1,key=len) 09/13 19:05