Skip to content

Commit 94b0816

Browse files
committed
improved solution for IterablesandIterators
1 parent 2577c46 commit 94b0816

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Itertools/IterablesandIterators.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
'''
8-
import itertools
8+
from itertools import *
9+
910
n = int(input())
10-
s_ar = input().strip().split()
11-
s = ''.join(s_ar)
11+
s = str(input())
1212
k = int(input())
13-
combination = list(itertools.combinations(s,k))
14-
combination_count = len(combination)
15-
a_count = 0
1613

17-
for single_combination in combination:
18-
if 'a' in single_combination:
19-
a_count += 1
20-
print(a_count / combination_count)
14+
pairs = list(combinations(s.split(),k))
15+
count = 0
16+
17+
for pair in pairs:
18+
if 'a' in pair:
19+
count += 1
20+
21+
print(count/len(pairs))

0 commit comments

Comments
 (0)