itertools.combinations_with_replacement()

Sort by

recency

|

520 Discussions

|

  • + 0 comments
    from itertools import combinations_with_replacement
    
    name, k = input().split()
    name = sorted(name)
    
    print(*list("".join(i) for i in sorted(combinations_with_replacement(name, int(k)))), sep="\n")
    
  • + 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))

  • + 0 comments

    from itertools import combinations_with_replacement as c

    n = input().split()

    string = n[0]

    size = int(n[1])

    sorted_string = ''.join(sorted(string))

    lst = [''.join(comb) for comb in c(sorted_string, size)]

    print(*lst, sep ="\n")

  • + 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))]
    
  • + 0 comments

    from itertools import combinations_with_replacement s, k = input().split() l = list(combinations_with_replacement(sorted(s),int(k))) for item in l: print(''.join(item))