Ash*_*ary -2 python list python-3.x
如何在一行中完成此操作.
b=[['1','2','3','4','5'],['11','12','13','14','15'],['6','7','8','9','10']]
c=[]
for x in b:
for y in x:
c.append(int(y))
c.sort()
print(c)
Run Code Online (Sandbox Code Playgroud)
预期产量:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Run Code Online (Sandbox Code Playgroud)
>>> b=[['1','2','3','4','5'],['11','12','13','14','15'],['6','7','8','9','10']]
>>> sorted(int(j) for i in b for j in i)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Run Code Online (Sandbox Code Playgroud)