Iterables and Iterators

Sort by

recency

|

936 Discussions

|

  • + 0 comments

    from itertools import combinations

    A = input() B = list(input().split(" ")) C = input()

    D = list(combinations(B, int(C)))

    count=0 for i in D: if "a" in i: count = count+1

    print(count/len(D))

  • + 0 comments
    from itertools import combinations
    
    N = input()
    S = input().split()
    K = int(input())
    ALL = list(combinations(S, K))
    COUNT = sum(1 for UNITS in ALL if 'a' in UNITS)
    print(round(COUNT/len(ALL), 4))
    
  • + 0 comments
    from itertools import combinations
    n = int(input())
    s = list(input().split(" "))
    k = int(input())
    count = 0
    for tup in combinations(s,k):
        if any(elem == 'a' for elem in tup):
            count += 1
    print(count / len(list(combinations(s,k))))
    
  • + 0 comments
    from itertools import combinations
    
    length = int(input())
    s = input().split()
    k = int(input())
    count = 0
    for tup in combinations(s,k):
        if any(elem == 'a' for elem in tup):
            count += 1
    
    print(count / len(list(combinations(s,k))))
    
  • + 0 comments

    This problem directing the old version documentation of itertools. It should be updated with the new version. https://docs.python.org/3.8/library/itertools.html