GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Write code for printing permutation of a string in python ?

asked Apr 7, 2016 by no3

4 Answers

You can made a recursive function for doing this :

def permutations(start, end=''):
    if len(start) == 0: 
        print end
    else:
        for i in range(len(start)):
            permutations(start[0:i] + start[i+1:], end + start[i])

permutations('1234')

 

answered Apr 7, 2016 by utkarsh111
import itertools

def premp(strs):
    perm = list("".join(string) for string in itertools.permutations("stack"))
    perm = list(set(perm)) 
    return perm
print premp('stack')

 

answered Apr 13, 2016 by Sengotian M

fdsgdsfgsdg

geeksforgeeks

 

answered Apr 27, 2016 by sdgfdsg
def perms(s):        
    if(len(s)==1): return [s]
    result=[]
    for i,v in enumerate(s):
        result += [v+p for p in perms(s[:i]+s[i+1:])]
    return result

print('\n'.join(perms('abc')))

 

answered Apr 27, 2016 by pranali_s
...