Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

get all subarrays of an array python

# Python program to print all
# sublist from a given list
from itertools import combinations
 
# function to generate all the sub lists
def sub_lists (l):
    # initializing empty list
    comb = []
     
    #Iterating till length of list
    for i in range(len(l)+1):
        # Generating sub list
        comb += [list(j) for j in combinations([1, 2, 3], i)]
    # Returning list
    return comb
 
# driver code
#Initial list
l1 = [1, 2, 3]
 
#Print initial list
print("Initial list is : " + str(l1))
 
# Calling function to generate all sub lists
print("All sub list is : "+ str(sub_lists(l1)))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #subarrays #array #python
ADD COMMENT
Topic
Name
2+8 =