itertools.combinations_with_replacement()

  • + 0 comments

    from itertools import combinations_with_replacement

    Reading input and splitting it into the string and integer r

    s, r = input().split()

    Sorting the string to ensure lexicographic order

    s = sorted(s)

    Generating and printing the combinations with replacement for combo in combinations_with_replacement(s, int(r)): print(''.join(combo))