Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Split list into chunks using List Comprehension

# Split a Python List into Chunks using list comprehensions
sample_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
chunk_size=2
result=[sample_list[i:i + chunk_size] for i in range(0, len(sample_list), chunk_size)]
print(result)
Comment

split into list into even chunks

def chunks(l, n):
    n = max(1, n)
    return (l[i:i+n] for i in range(0, len(l), n))
Comment

PREVIOUS NEXT
Code Example
Python :: for loop with float python 
Python :: ubuntu install pip for python 3.8 
Python :: how to reset a variable in python 
Python :: matplotlib ticksize 
Python :: change python 3.5 to 3.6 ubuntu 
Python :: np array describe 
Python :: pandas query variable count 
Python :: python format to print dec oct hex and bin 
Python :: exact distance math 
Python :: how to open a website with selenium python 
Python :: how to clear screen python 
Python :: pil image from numpy 
Python :: opencv imshow resize 
Python :: python convert datetime.timedelta into seconds 
Python :: python n choose r 
Python :: undo cell delete kaggle 
Python :: python remove directory not empty 
Python :: how to take two integers as input in python 
Python :: sort by index pandas 
Python :: python google search results 
Python :: dict to array of string python 
Python :: ordered char list 
Python :: mean code python 
Python :: pygame doesnt dedect collision between sprite and image 
Python :: count number of words in a string python 
Python :: python class tostring 
Python :: django delete session 
Python :: decision tree gridsearchcv 
Python :: np replace nan 
Python :: all column except pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =