Iterables and Iterators

  • + 0 comments
    from itertools import combinations
    
    N = int(input())
    N_list = input().split()
    K = int(input())
    
    # Generate all combinations once
    combs = list(combinations(N_list, K))
    
    # Count the combinations that contain 'a'
    counter = sum(1 for pair in combs if 'a' in pair)
    
    # Print the ratio of valid combinations
    print(counter / len(combs))