به Nostr بپیوندید
2026-05-10 19:46:00 CEST

Trey Hunner 🐍 on Nostr: Python Tip #130 (of 365): Only use recursion for trees Recursion is most useful for ...

Python Tip #130 (of 365):

Only use recursion for trees

Recursion is most useful for traversing or constructing TREE-LIKE STRUCTURES.

For most other problems, iteration is usually more readable.

Recursion is when a function calls itself.

Computer science classes almost always introduce recursion using factorial or fibonacci. Those are not great examples because those are both very clear (and fast) using a simple "for" loop instead.

🧵 (1/6)

#Python #DailyPythonTip