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))




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube