cube =lambdax: pow(x, 3)deffibonacci(n): numbers = []for i inrange(n):if i <=1: numbers.append(i)else: numbers.append(numbers[len(numbers)-1] + numbers[len(numbers)-2])return numbersif__name__=='__main__': n =int(input())print(list(map(cube, fibonacci(n))))
Validating Email Address with a Filter
import redeffun(s):# return True if s is a valid email, else return Falseif re.match(r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$', s):returnTrueelse:returnFalsedeffilter_mail(emails):returnlist(filter(fun, emails))if__name__=='__main__': n =int(input()) emails = []for _ inrange(n): emails.append(input())filtered_emails =filter_mail(emails)filtered_emails.sort()print(filtered_emails)
Reduce Function
from fractions import Fractionfrom functools import reducedefproduct(fracs): t =reduce(lambdax, y: x * y, fracs)return t.numerator, t.denominatorif__name__=='__main__': fracs = []for _ inrange(int(input())): fracs.append(Fraction(*map(int, input().split()))) result =product(fracs)print(*result)