Input Format
The input consists of three lines. The first line contains the integer , denoting the length of the list. The next line consists of  space-separated lowercase English letters, denoting the elements of the list.
The third and the last line of input contains the integer , denoting the number of indices to be selected.
Output Format
Output a single line consisting of the probability that at least one of the  indices selected contains the letter:''.
Note: The answer must be correct up to 3 decimal places.
Constraints
All the letters in the list are lowercase English letters.

Hackerrank iterables and iterators problem solution in python

Problem solution in python 2 programming language.

from itertools import combinations 

N = int(input())
S = raw_input().split(' ')
K = int(input())

num = 0
den = 0

for c in combinations(S,K):
    den+=1
    num+='a' in c
    
print float(num)/den

Problem solution in python 3 programming language.

from itertools import combinations
N = int(input())
L = input().split()
K = int(input())
C = list(combinations(L, K))
F = filter(lambda c: 'a' in c, C)
print("{0:.3}".format(len(list(F))/len(C)))