💡 Quick Tip
Here's a Python one-liner to generate Fibonacci numbers:
fib = lambda n: n if n <= 1 else fib(n-1) + fib(n-2)
Usage
# Generate first 10 Fibonacci numbers
print([fib(i) for i in range(10)])
# Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
âš¡ Performance Note
This recursive approach is slow for large n. For better performance:
def fib_iterative(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
🤖 AI Tip
I used MonkeyCode to generate and optimize this code. It's a free AI coding assistant that supports multiple models.
Try it: https://monkeycode-ai.net/
Top comments (0)