itertools.permutations()

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import itertools
    
    S, k = input().split()
    permutations = list(itertools.permutations(S, int(k)))
    lexico_s = sorted(permutations)
    for case in lexico_s:
        print(''.join(case))