Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

split array into chunks python

a = [1, 2, 3, 4, 5, 6 ,7 ,8 ,9]

splitedSize = 3
a_splited = [a[x:x+splitedSize] for x in range(0, len(a), splitedSize)]

print(a_splited)
# [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Comment

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 :: pandas dataframe.to_dict 
Python :: Python from...import statement 
Python :: get tweet by its id 
Python :: tweepy auth 
Python :: how to check dimension of array in python 
Python :: tkinter window size position 
Python :: in dataframe particular column to string 
Python :: making gifs via python 
Python :: reverse python 
Python :: python get current date and time 
Python :: print random integers py 
Python :: generate random password django 
Python :: play music pygame 
Python :: python pandas in list 
Python :: legend text color matplotlib 
Python :: check if the user is logged in django decorator 
Python :: datetime.time to seconds 
Python :: python division 
Python :: how to exit program in python 
Python :: python datetime get date one week from today 
Python :: combine two columns pandas 
Python :: generate rsa key python 
Python :: django pass parameters in url 
Python :: tuple comprehension python 
Python :: python shuffle 
Python :: heroku requirements.txt python 
Python :: python async await run thread 
Python :: django order by foreign key count 
Python :: sendgrid django smtp 
Python :: how to clear dictionary in python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =