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

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

hackerrank itertools combinations problem solution in python programming

Problem solution in Python 3 programming language.

from itertools import combinations
S,k = input().split()
for j in range(1,int(k)+1):
    for i in combinations(sorted(S),j):
        print("".join(i))

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import combinations
s , n  = input().split()
for i in range(1int(n)+1):
    for j in combinations(sorted(s), i):
        print(''.join(j))

Problem solution in Python 2 programming language.

from itertools import combinations
S,k = raw_input().split()
for j in range(1,int(k)+1):
    for i in combinations(sorted(S),j):
        print "".join(i)