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 :: display column names as a dictionary pandas 
Python :: horizontal barplot 
Python :: jupyter dataframe print all 
Python :: get legend lables and handles from plot in matplotlib 
Python :: turn off yticklabels 
Python :: python np array get dimantion 
Python :: compiling python code 
Python :: get first not null value from column dataframe 
Python :: gene wilder pure imagination 
Python :: convert plt.show to image to show opencv 
Python :: Write a simple python program that adds 2 numbers togethe 
Python :: python how to add a new key to a dictionary 
Python :: newtorkx remove node 
Python :: fit function tensorflow 
Python :: python regex find single character 
Python :: how to loop function until true python 
Python :: check command 
Python :: how to make a static variable in python 
Python :: recall at k calculate python 
Python :: normal discord.py codes 
Python :: Working with WTForms FieldList 
Python :: call shell script from python 
Python :: boder color in tkinter 
Python :: python re.findall() 
Python :: change excel value in python 
Python :: how to pre populate field flask wtforms 
Python :: authentication serializer drf 
Python :: python set workspace dir 
Python :: python find oldest and newest date 
Python :: newsapi 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =