HackerRank Python - Map and Lambda Function

The map() function applies a function to every member of an iterable and returns the result. It takes two parameters: first, the function that is to be applied and secondly, the iterables.
Let's say you are given a list of names, and you have to print a list that contains the length of each name.

  1. cube = lambda x: x ** 3
  2. def fibonacci(n):
  3. a, b, c = 0, 1, 1
  4. for _ in range(n):
  5. yield a
  6. a, b = b, a + b
  7. if __name__ == '__main__':
  8. n = int(input())
  9. print(list(map(cube, fibonacci(n))))

download android app