Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Backtracking Python

def permutation(list, start, end):
    '''This prints all the permutations of a given list
       it takes the list,the starting and ending indices as input'''
    if (start == end):
        print list
    else:
        for i in range(start, end + 1):
            list[start], list[i] = list[i], list[start]  # The swapping
            permutation(list, start + 1, end)
            list[start], list[i] = list[i], list[start]  # Backtracking


permutation([1, 2, 3], 0, 2)  # The first index of a list is zero
Comment

PREVIOUS NEXT
Code Example
Python :: euclidean distance python 3 variables 
Python :: max in a list python 
Python :: select columns to include in new dataframe in python 
Python :: build a pile of cubes python 
Python :: matplotlib orange line 
Python :: delete a column in pandas 
Python :: if main 
Python :: python dict setdefault 
Python :: join dataframe pandas by column 
Python :: how to make an empty variable in python 
Python :: how can i plot graph from 2 dataframes in same window python 
Python :: discord.py send image from url 
Python :: variable in python 
Python :: how to search in django 
Python :: python thread function 
Python :: create a timestamp python 
Python :: filter django or 
Python :: get name of month python 
Python :: how to get length of string in python 
Python :: turn python script into exe 
Python :: how to add new column in csv file using pandas 
Python :: How to join train and Test dataset in python 
Python :: string format zero padded int python 
Python :: Returns the first n rows 
Python :: Creating a donut plot python 
Python :: if number is divisible by 3 python 
Python :: django get parameters from url 
Python :: strftime python multiple formats 
Python :: access list items in python 
Python :: Iterate string 2 characters at a time in python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =