Demo entry 6344589

test

   

Submitted by anonymous on Jan 17, 2017 at 06:54
Language: Python. Code size: 352 Bytes.

def sub_lists(my_list):  
    subs = [[]]  
    for i in range(len(my_list)):  
        n = i+1  
        while n <= len(my_list):  
            sub = my_list[i:n]  
            subs.append(sub)  
            n += 1  
      
    return subs  
  
l1 = [10, 20, 30, 40]  
l2 = ['X', 'Y', 'Z']  
print(sub_lists(l1))  
print(sub_lists(l2))  

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).