0% found this document useful (0 votes)
881 views1 page

Map and Lambda Function Problem Solution - Python - Hackerrank

This document contains two Python code solutions for a problem on HackerRank involving map and lambda functions. The first solution calculates the first N Fibonacci numbers, maps a lambda function to cube each number, and prints the results. The second solution defines a lambda function to cube a number, a fibonacci function to generate the first N Fibonacci numbers, and then maps the cubing lambda function to the fibonacci list and prints the results.

Uploaded by

Sagar Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
881 views1 page

Map and Lambda Function Problem Solution - Python - Hackerrank

This document contains two Python code solutions for a problem on HackerRank involving map and lambda functions. The first solution calculates the first N Fibonacci numbers, maps a lambda function to cube each number, and prints the results. The second solution defines a lambda function to cube a number, a fibonacci function to generate the first N Fibonacci numbers, and then maps the cubing lambda function to the fibonacci list and prints the results.

Uploaded by

Sagar Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Map and Lambda Function problem solution | Python | HackerRank

Problem solution in Python 3 programming language.

# Enter your code here. Read input from STDIN. Print output to STDOUT
N = int(input())
A = [0,1]
for i in range(2,N): A.append(A[i-1]+A[i-2])
print(map(lambda a: a*a*a,A)[:N])

Second solution

cube = lambda x: pow(x,3)# complete the lambda function 

def fibonacci(n):

    # return a list of fibonacci numbers

    lis = [0,1]

    for i in range(2,n):

        lis.append(lis[i-2] + lis[i-1])

    return(lis[0:n])

if __name__ == '__main__':

    n = int(input())

    print(list(map(cube, fibonacci(n))))

You might also like