itertools.combinations_with_replacement()

  • + 1 comment
    from itertools import combinations_with_replacement
    S, k = input().split()
    [print(''.join(x)) for x in combinations_with_replacement(sorted(S), int(k))]