Q:

pythonic way to split list? 

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

I Have a function like below:
def split_list(self,my_list,num):    
    .....    
    .....

where my_list is: 
my_list = [['1','one'],['2','two'],['3','three'],['4','four'],['5','five'],['6','six'],['7','seven'],['8','eight']]

I want to split list by given num:
i.e if num = 3
then output will be :  [[['1','one'],['2','two'],['3','three']],[['4','four'],['5','five'],['6','six']],[['7','seven'],['8','eight']]]
if num =4 then 
[[['1','one'],['2','two'],['3','three'],['4','four']],[['5','five'],['6','six'],['7','seven'],['8','eight']]]

A:

I'd just use a list comprehension/generator:
[my_list[x:x+num] for x in range(0, len(my_list), num)]

