Input Format
A single line containing the space separated string  and the integer value .
Constraints

The string contains only UPPERCASE characters.
Output Format
Print the permutations of the string  on separate lines.

hackerrank itertools permutations problem solution in python programming

Problem solution in python 2 programming language.

from itertools import *
S, k = raw_input().split()
for i in permutations(sorted(S),int(k)):
    print("".join(i))

Problem solution in python 3 programming language.

from itertools import *
S, k = input().split()
for i in permutations(sorted(S),int(k)):
    print("".join(i))

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import permutations
s,n = input().split()
print(*[''.join(i) for i in permutations(sorted(s),int(n))],sep='\n')