Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

all subarrays of an array python

import itertools

def allSubArrays(xs):
    n = len(xs)
    indices = list(range(n+1))
    for i,j in itertools.combinations(indices,2):
        yield xs[i:j]
Comment

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)))
Comment

PREVIOUS NEXT
Code Example
Python :: read xls file in python 
Python :: python time in nanoseconds 
Python :: python utf8 
Python :: selenium python 
Python :: define variable with if statement python 
Python :: python move item in list to end 
Python :: how to increment date by one in python 
Python :: python code to open windows command prompt 
Python :: python write to file csv 
Python :: how to count in a loop python 
Python :: django phone number field 
Python :: how to check the type of a variable in python 
Python :: remove blank spaces from a list python 
Python :: python write txt utf8 
Python :: python string contains substring 
Python :: mad python 
Python :: remove nans from array 
Python :: how to draw in pygame 
Python :: pandas replace zero with blank 
Python :: telnet python 
Python :: create a list of characters python 
Python :: how to show pandas last record 
Python :: python candlestick chart 
Python :: Delete the node at a given position 2 in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, return a null value. 
Python :: discord py get user by id 
Python :: ipython read audio file 
Python :: drop nulll python 
Python :: export_excel file python 
Python :: python emojis 
Python :: sum values in django models 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =