How do you split a list into evenly sized chunks in Python?

list
python

#1

How do you split a list into evenly sized chunks in Python?


#2

Hi @deepak_wns,

You could write a simple list comprehension for it;

list_of_lists = [original_list[i:i + chunk_size] for i in xrange(0, len(original_list), chunk_size)]

#3

why in Python. Most Unix Researchers use native shell commands like “split file” etc
https://kb.iu.edu/d/afar