Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Permutation without built-in function [itertools] for Lists

def permutation(list1):  
   # If the length of list=0 no permuataions possible 
   if len(list1) == 0:  
       return []  
   # If the length of list=1, return that element 
   if len(list1) == 1:  
       return [list1]  
   l = []  
   for i in range(len(list1)):  
       m = list1[i]  
      # Extract list1[i] or m from the list. remlist1 is  
      # remaining list  
       remlist1 = list1[:i] + list1[i+1:]  
      # Generating all permutations where m is first  
      # element  
       for p in permutation(remlist1):  
            l.append([m] + p)  
   return l 
if __name__=="__main__": 
   print(list(permutation([1,2,3,4])))
Comment

PREVIOUS NEXT
Code Example
Python :: Print characters from a string that are present at an even index number 
Python :: Django Redirect Depending On Request Method 
Python :: input and print 
Python :: Sqlalchemy Define class from existing table 
Python :: covert docx to pdf with libraoffice in python 
Python :: python remove table widget numbers 
Python :: python 3.7 download 
Python :: Range all columns of df such that the minimum value in each column is 0 and max is 1. in pandas 
Python :: Object of type datetime is not JSON serializable 
Python :: change group box border color pyqt5 
Python :: python serial COM3 
Python :: mathtext to regular python 
Python :: python integers 
Python :: python += dictionary 
Python :: 151 - Power Crisis solution in python 
Python :: python inspect.getsource 
Python :: length of dictionary python 
Python :: pandas flip x and y axis 
Python :: where are docker logs 
Python :: python reading into a text file and diplaying items in a user friendly manner 
Python :: how to input a full array in one input in python 
Python :: python one line key increment or add 
Python :: how to create multiple file in python using for loop. 
Python :: boto3 upload dataframe directly to s3 
Python :: datetime to timestamp 
Python :: how to implement heap in python 
Python :: ascii values in python of 
Python :: django pycharm 
Python :: na.fill pyspark 
Python :: if in one line python 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =