Skip to content

Commit ce10bfa

Browse files
authored
Merge pull request #2 from hernandanielg/master
Updated List Comprehensions and Iterables and Iterators
2 parents 2577c46 + 4faa68d commit ce10bfa

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

DataTypes/ListComprehensions.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,4 @@
1010
y=int(raw_input())
1111
z=int(raw_input())
1212
n=int(raw_input())
13-
final_ar=[]
14-
for i in range(0,x+1):
15-
for j in range(0,y+1):
16-
for k in range(0,z+1):
17-
tmp=i+j+k
18-
if(tmp!=n):
19-
ar=[i,j,k]
20-
final_ar.append(ar)
21-
22-
print final_ar
13+
print([ [i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k != n ])

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)