itertools.combinations()

Sort by

recency

|

934 Discussions

|

  • + 0 comments
    from itertools import combinations, chain
    
    string, size = input().split()
    
    size = int(size)
    
    sorted_string = sorted(string)
    
    print(
        "\n".join(
            "".join(combination)
            for combination in chain.from_iterable(
                combinations(sorted_string, r) for r in range(1, size + 1)
            )
        )
    )
    
  • + 0 comments

    from itertools import combinations

    A, B = input().split(" ")

    A = sorted(A)

    for i in range(1, int(B)+1): F = list(combinations(A, i)) for i in F: print("".join(i))

  • + 0 comments

    For Python3 Platform

    import itertools
    
    s, k = input().split()
    
    for i in range(1, int(k)+1):
        comb = itertools.combinations(sorted(s), i)
        
        for c in comb:
            print("".join(c))
    
  • + 0 comments

    from itertools import combinations

    a , b = input().split() b = int(b)

    for s in range(1,b+1): for j in combinations(sorted(a),s): print(*j,sep="")

  • + 0 comments

    ' from itertools import combinations

    S,k=input().split(" ") for i in range(int(k)):

    for ele in combinations(sorted(S),int(i+1)):
        print(''.join(ele))
    

    '