Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

HackerRank Map and Lambda Function solution in python

YASH PAL, 31 July 2024

In this Map and Lambda Function problem, You have to generate a list of the first N Fibonacci numbers, 0 being the first number. Then, apply the map function and a lambda expression to cube each Fibonacci number and print the list.

HackerRank Map and Lambda Function solution in python

Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
def fib(n):
	if n == 0:
		return 0
	if n == 1:
		return 1
	return fib(n-2) + fib(n-1)
n = int(raw_input())
cube = lambda x: x*x*x
print list(map(cube,[fib(a) for a in xrange(n)]))

Problem solution in Python 3 programming.

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])

Problem solution in pypy programming.

cube = lambda x: x**3

def fibonacci(n):
    # return a list of fibonacci numbers
    result = [0,1]
    for i in range(2,n):
        result.append(result[i-1]+result[i-2])
        
    return result[:n]

Problem solution in pypy3 programming.

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])

coding problems solutions Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes