In this itertools.permutations() problem we need to develop a python program that can read an string as input and then we need to print all the possible permutations of size k of string in lexographic sorted order.

# Problem solution in Python 2 programming.

from itertools import permutations S,k = raw_input().split() k = int(k) print '\n'.join(sorted(''.join(p) for p in permutations(S,k)))

## Problem solution in Python 3 programming.

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

### Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT from itertools import permutations string_number = raw_input().split() string = string_number[0] number = map(int, string_number[1]) for elem in sorted(list(permutations(string, number[0]))): n = len(elem) elem_print = "" for i in range(0, n): elem_print+=elem[i] print elem_print

### Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT import itertools ll, n = input().split() for i in itertools.permutations(sorted(ll),int(n)): print("".join(i))

## 0 Comments