itertools.combinations()

Sort by

recency

|

906 Discussions

|

  • + 0 comments
    from itertools import combinations
    
    s, k = input().split()
    for i in range(1,int(k)+1):
        for combo in combinations(sorted(s),i):
            print("".join(combo))
    
  • + 0 comments
    from itertools import combinations
    
    # Read input
    data = input().split()
    word = sorted(data[0])  # Sort characters in words
    length = int(data[1])  # Take the length of the combinations
    
    # Display the output in the desired format
    for i in range(1, length + 1):
        result = combinations(word, i)
        for comb in result:
            print("".join(comb))
    
  • + 1 comment
    from itertools import combinations
    mystr, k=list(input().split(' '))
    string = sorted(mystr)
    for x in range(1,int(k)+1):
        res = list(combinations(string, x))
        for i in sorted(res):
            restr = ''.join(i)
            print(restr)
        rest = ''
    
    • + 0 comments

      Hi, bro.

      When you use split(), it returns a list, so you don't need to use list().

  • + 0 comments

    been practicing again with python. not the simplest one, big hope to be more advance.

    from itertools import combinations
    
    def combination(numbers):
        arr = [] 
        val = sorted(numbers[0])
    
        for x in range(1, int(numbers[1])+1):
            comb = sorted(list(combinations(val, x)))
            for x in comb:
                res = arr.append("".join(x))
        return(arr)
                
    if __name__ == "__main__":
        numbers = input().split()
        res = combination(numbers)
        for x in res:
            print(x)
    
  • + 0 comments

    from itertools import combinations s,k=input().split() k1=int(k) s1=list(s) s1.sort() for i in range(0,k1): p=list(combinations(s1,i+1)) for i in p: j="".join(i) print(j)