We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Map and Lambda Function
Map and Lambda Function
+ 0 comments cube = lambda x: x**3 def fibonacci(n): # return a list of fibonacci numbers lst = [0, 1] if n >= 3: for _ in range(n-len(lst)): lst.append(lst[-1] + lst[-2]) return lst elif n == 0: return [] else: return lst[:n] if __name__ == '__main__': n = int(input()) print(list(map(cube, fibonacci(n))))
+ 0 comments cube = lambda x: x**3 def fibonacci(n): a, b = 1,0 temp = [] for _ in range(n): a, b = b, a+b temp.append(a) return temp
+ 0 comments cube = lambda x: x**3 def fibonacci(n): if n == 0: return [] elif n == 1: return [0] elif n == 2: return [0, 1] else: lis = [0, 1] while len(lis) < n: lis.append(lis[-1]+lis[-2]) return lis if __name__ == '__main__':
+ 0 comments cube = lambda x: x**3 def fibonacci(n): if n==0: l=[] elif n==1: l=[0] else: l=[0,1] for i in range(n-2): l.append(l[i]+l[i+1]) return l
+ 0 comments cube = lambda x: x**3 from functools import reduce def fibonacci(n): if n == 0: return [] elif n == 1: return [0] # return a list of fibonacci numbers res = [0, 1] return reduce(lambda x, _: x + [x[-2] + x[-1]], range(n - 2), res)
Load more conversations
Sort 424 Discussions, By:
Please Login in order to post a comment