Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #以下方法使用 range() 将列表分块为指定大小的较小列表。
  2.  
  3. from math import ceil
  4.  
  5. def chunk(lst, size):
  6. return list(
  7. map(lambda x: lst[x * size:x * size + size],
  8. list(range(0, ceil(len(lst) / size)))))
  9. chunk([1,2,3,4,5],2) # [[1,2],[3,4],5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement