We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Iterables and Iterators
Iterables and Iterators
Sort by
recency
|
904 Discussions
|
Please Login in order to post a comment
n = int(input()) # Length of the list letters = input().split() # List of letters k = int(input()) # Number of indices to select
comb = list(combinations(letters, k)) favorable = sum(1 for group in comb if 'a' in group) probability = favorable / len(comb) print(f"{probability:.3f}")
from itertools import combinations
N, S, K = int(input()), list(input().split()), int(input())
S=''.join(S) combs = list(combinations(S, K)) tups = [p for p in combs if 'a' in p] print(round(len(tups)/len(combs),3))