Chunks a list into smaller lists of a specified size in Python #Shorts

preview_player
Показать описание
Use list and range to create a list of the desired size.
Use map on the list and fill it with splices of the given list.
Finally, return the created list.

#Shorts #Python #chunks
Рекомендации по теме
Комментарии
Автор

You could just do
chunks = [lst[i:i+c] for i in range(0, len(lst), c)]
Where c is the chunk size. List comprehension is almost always faster and more memory efficient than map. Lambda makes it further less efficient

damleman
visit shbcf.ru