Skip to content

Commit 6033e2c

Browse files
committed
Python Functionals 1-3
1 parent d2ad0f1 commit 6033e2c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Map and Lambda Function
2+
# https://www.hackerrank.com/challenges/map-and-lambda-expression/problem
3+
4+
fib = lambda y: y if y < 2 else fib(y - 1) + fib(y - 2)
5+
print(list(map(lambda x: x**3, map(fib, range(int(input().strip()))))))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Reduce Function
2+
# https://www.hackerrank.com/challenges/reduce-function/problem
3+
4+
from fractions import Fraction
5+
from functools import reduce
6+
7+
def product(fracs):
8+
t = Fraction(reduce(lambda x,y : x*y,fracs))
9+
return t.numerator, t.denominator
10+
11+
if __name__ == '__main__':
12+
fracs = []
13+
for _ in range(int(input())): fracs.append(Fraction(*map(int, input().split())))
14+
result = product(fracs)
15+
print(*result)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Validating Email Addresses With a Filter
2+
# https://www.hackerrank.com/challenges/validate-list-of-email-address-with-filter/problem
3+
4+
import re
5+
6+
addr = re.compile('''^[\w-]{1,}@[a-zA-Z0-9]{1,}\.\w{1,3}$''', re.UNICODE | re.VERBOSE)
7+
print(sorted(filter(addr.search, (input() for _ in range(int(input()))))))

0 commit comments

Comments
 (0)