itertools.combinations_with_replacement()

  • + 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")