Iterables and Iterators

  • + 0 comments
    from itertools import combinations
    n = int(input())
    eng_list = input().split()  
    k = int(input())
    index_a = [i+1 for i,j in enumerate(eng_list)if j=='a']
    comb = list(combinations(range(1,len(eng_list)+1), k))
    count = 0
    for j in comb:
        if any(i in j for i in index_a):
            count+=1
    prob = count/len(comb)
    print(round(prob,11))