Iterables and Iterators

  • + 0 comments
    from itertools import combinations
    def probability(letter, K):
        final = list(combinations(letter,K))
        count = 0 
        for i in range(len(final)):
            if 'a' in final[i]:
                count += 1 
        prob = count/len(final)
        return prob
        
    if __name__ == "__main__":
        N = int(input())
        letter = list(input().split())
        K = int(input())
        result = probability(letter,K)
        print(result)