Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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

# Recursive function to generate all permutations of a string
def permutations(remaining, candidate=''):
 
    if len(remaining) == 0:
        print(candidate)
 
    for i in range(len(remaining)):
 
        newCandidate = candidate + remaining[i]
        newRemaining = remaining[0:i] + remaining[i+1:]
 
        permutations(newRemaining, newCandidate)
 
if __name__ == '__main__':
 
    s = 'ABC'
    permutations(s)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Python #Permutation #function #String
ADD COMMENT
Topic
Name
3+3 =