breaking a list into smaller lists

Bart Nessux bart_nessux at hotmail.com
Wed Jun 16 21:13:25 EDT 2004


Maciej Dziardziel wrote:
> 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
> 

Thank you for this example. It works very well.



More information about the Python-list mailing list