breaking a list into smaller lists

Bart Nessux bart_nessux at
Thu Jun 17 01:04:10 CEST 2004

I understand how a Python list can be broken into smaller lists by using 
slice like this:

new_small_list_1 = BIG_LIST[0:1001]		#0-1000
new_small_list_2 = BIG_LIST[1001:2001]		#1001-2000
new_small_list_3 = BIG_LIST[2001:3001]		#2001-3000

However, I was wondering if there's an easier way to do this. For 
example, say I have a list that contains the names of 100,000 files that 
I wish to open and read. Because of file handle limits, I can only open 
roughly 1000 files at a time while the OS is doing other things.

Is there a way to turn this big list into 100 small lists (each 
containing 1000 files) with one simple line of code?


More information about the Python-list mailing list