You are viewing a single comment's thread. Return to all comments →
import itertools as it
length = int(input()) chars = list(input().split()) size = int(input())
combos = list(it.combinations(chars, size)) count1 = 0 for item in combos: count2 = 0 for numb in range(len(item)): if item[numb] == 'a': count2 += 1 if count2 >= 1: count1 += 1 print(str((count1/len(combos))))
Seems like cookies are disabled on this browser, please enable them to open this website
Iterables and Iterators
You are viewing a single comment's thread. Return to all comments →
import itertools as it
length = int(input()) chars = list(input().split()) size = int(input())
combos = list(it.combinations(chars, size)) count1 = 0 for item in combos: count2 = 0 for numb in range(len(item)): if item[numb] == 'a': count2 += 1 if count2 >= 1: count1 += 1 print(str((count1/len(combos))))