HackerRank Python - itertools.permutations()



You are given a string S.
Your task is to print all possible permutations of size K of the string in lexicographic sorted order.



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from itertools import permutations
  3. ip=input().split()
  4. s=ip[0]
  5. k=int(ip[1])
  6. ans= list(permutations(s,k))
  7. for i in sorted(ans):
  8. print ("".join(i))

download android app