breaking a list into smaller lists

Maciej Dziardziel fiedzia at
Thu Jun 17 02:10:48 CEST 2004

Bart Nessux wrote:

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

big = range(87)

print  [ big[i*10:i*10+10] for i in xrange(len(big)/10+int((len(big) %
10)>0) ) ]

replace 10 with any value you need, but it is better not to keep all 100 000
filenames  in memory if it isn't necessary

Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)

More information about the Python-list mailing list