Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

batch a list python

l = [1,2,3,4,5,6,7,8,9,10]
batch_size = 3    

for i in range(0, len(l), batch_size):
    print(l[i:i+batch_size])
    # i skip 3 (batch) on each itteration
    # l[0: 0+batch]
    # l[batch: batch+batch] ... 

>>> [1,2,3]
>>> [4,5,6]
>>> [7,8,9]
>>> [10]
Comment

PREVIOUS NEXT
Code Example
Python :: delete a record by id in flask sqlalchemy 
Python :: convert time zone pandas 
Python :: order dataframe by multiple columns python 
Python :: pytest installation windows 
Python :: installing fastapi 
Python :: askopenfilename 
Python :: how to reset a variable in python 
Python :: python check if value is undefined 
Python :: python localhost 
Python :: how to obtain the content of brackets 
Python :: how to make all time greeter using python 
Python :: how to open a website with selenium python 
Python :: how to get current page url in django template 
Python :: create directory python if not exist 
Python :: how to split a string in python with multiple delimiters 
Python :: python subtract 2 strings 
Python :: saving to csv without the index 
Python :: remove warnings from jupter notebook 
Python :: np zeros in more dimensions 
Python :: unpack dictionaryp 
Python :: how to create list from a to z in python 
Python :: django import settings variables 
Python :: char list 
Python :: python remove during iteration 
Python :: numpy ones 
Python :: append row to array python 
Python :: encoding read_csv 
Python :: python get pixel color 
Python :: floyd triangle python 
Python :: Difference between end and sep python 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =