itertools.combinations()

Sort by

recency

|

888 Discussions

|

  • + 0 comments

    from itertools import combinations

    Read input

    S, k = input().split() k = int(k)

    Sort the string to ensure lexicographic order

    S = ''.join(sorted(S))

    Generate and print combinations for each length from 1 to k

    for i in range(1, k + 1): for combo in combinations(S, i): print(''.join(combo))

  • + 0 comments

    from itertools import combinations

    def permutation(): user_input = input() input_list = user_input.split() var1, k = input_list[0], int(input_list[1]) sorted_var1 = "".join(sorted(var1)) for size in range(1, k + 1): for combo in combinations(sorted_var1, size): print("".join(combo))

    if name == "main": permutation()

  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    from itertools import product import itertools import sys

    input_data = sys.stdin.read().strip()

    A, B = input_data.split() B = int(B)

    A_sort = ''.join(sorted(A))

    ''''''

    for j in A_sort: print(j)

    for x in range(2, B+1): perm_set = itertools.combinations(A_sort,x) for i in perm_set: print(''.join(i))

  • + 0 comments

    from itertools import combinations

    st = input().split()

    s = st[0]

    k = int(st[1])

    sorted_string = sorted(s)

    for i in range(1, k+1):

    for combo in combinations(sorted_string, i):

    print(''.join(combo))
    
  • + 0 comments
    from itertools import combinations as com
    l,p = input().split()
    l = sorted(l)
    for i in range(int(p)):
        b = list(com(l,(int(i) + 1)))
        for k in b:
            print(''.join(k))