Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python list chunks using yield

def split(list_a, chunk_size):

  for i in range(0, len(list_a), chunk_size):
    yield list_a[i:i + chunk_size]

chunk_size = 2
my_list = [1,2,3,4,5,6,7,8,9]
print(list(split(my_list, chunk_size)))
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #python #list #chunks #yield
ADD COMMENT
Topic
Name
3+5 =