The Real Python Podcast

Exploring Recursion in Python With Al Sweigart


Listen Later

Have you wanted to understand recursion and how to use it in Python? Are you familiar with the call stack and how it relates to tracebacks? This week on the show, Al Sweigart talks about his new book, “The Recursive Book of Recursion.”

Recursion is one of those concepts held as a tenet of high-level computer science priesthood. Al explains the fundamentals of writing recursive functions and a critical missing piece in understanding how they operate, the call stack. After completing his research, he concluded that it’s a technique that you should understand but rarely use.

He also shares the few cases where recursion is an appropriate solution. Along the way, we talk about directed acyclic graphs, solving mazes, exploring file trees, and creating fractal images.

Course Spotlight: Caching in Python With lru_cache

Caching is an essential optimization technique. In this video course, you’ll learn how to use Python’s @lru_cache decorator to cache the results of your functions using the LRU cache strategy. This is a powerful technique you can use to leverage the power of caching in your implementations.

Topics:

  • 00:00:00 – Introduction
  • 00:01:55 – The Recursive Book of Recursion
  • 00:02:55 – A Beginner’s Guide to Recursion - YouTube
  • 00:05:41 – What is recursion?
  • 00:10:17 – Understanding the call stack
  • 00:12:15 – Languages moving from GOTO statements to functions and a stack
  • 00:21:11 – A common recursion example of factorials
  • 00:26:00 – Fibonacci sequence and memoization
  • 00:30:25 – Cautionary advice on applying recursion
  • 00:32:55 – What is recursion useful for?
  • 00:39:56 – Video Course Spotlight
  • 00:41:14 – Recursion and directed acyclic graphs
  • 00:45:46 – Book examples
  • 00:49:50 – Thoughts on tail recursion
  • 00:54:34 – How has the scope of the book evolved?
  • 01:00:34 – Creating examples in two languages
  • 01:02:37 – Upcoming projects
  • 01:05:19 – Examples of the projects in the book
  • 01:10:30 – What are you excited about in the world of Python?
  • 01:14:50 – What do you want to learn next?
  • 01:19:06 – How can people follow your work?
  • 01:19:48 – Thanks and goodbye
  • Show Links:

    • The Recursive Book of Recursion | No Starch Press
    • Recursion for Beginners: A Beginner’s Guide to Recursion - YouTube
    • The Invent with Python Blog
    • Recursion in Python
    • factorial | Definition, Symbol, & Facts | Britannica
    • Fibonacci sequence | Definition, Formula, Numbers, Ratio, & Facts | Britannica
    • A Python Guide to the Fibonacci Sequence – Real Python
    • Directed acyclic graph - Wikipedia
    • Dynamic programming - Wikipedia
    • The Little Schemer : Friedman, Daniel P : Internet Archive
    • Book Review: The Little Schemer - The Invent with Python Blog
    • Droste effect - Wikipedia
    • Episode #33: Going Beyond the Basic Stuff With Python and Al Sweigart – The Real Python Podcast
    • Textualize
    • Episode #80: Make Your Python App Interactive With a Text User Interface (TUI) – The Real Python Podcast
    • BeeWare — Write once. Deploy everywhere.
    • Episode #22: Create Cross-Platform Python GUI Apps With BeeWare – The Real Python Podcast
    • Origami with Jo Nakashima - YouTube
    • Invent with Python
    • Level up your Python skills with our expert-led courses:

      • Grow Your Python Portfolio With 13 Intermediate Project Ideas
      • Caching in Python With lru_cache
      • Exploring the Fibonacci Sequence With Python
      • Support the podcast & join our community of Pythonistas

        ...more
        View all episodesView all episodes
        Download on the App Store

        The Real Python PodcastBy Real Python

        • 4.7
        • 4.7
        • 4.7
        • 4.7
        • 4.7

        4.7

        136 ratings


        More shows like The Real Python Podcast

        View all
        Software Engineering Radio - the podcast for professional software developers by se-radio@computer.org

        Software Engineering Radio - the podcast for professional software developers

        272 Listeners

        The Changelog: Software Development, Open Source by Changelog Media

        The Changelog: Software Development, Open Source

        283 Listeners

        Thoughtworks Technology Podcast by Thoughtworks

        Thoughtworks Technology Podcast

        41 Listeners

        Talk Python To Me by Michael Kennedy

        Talk Python To Me

        592 Listeners

        Software Engineering Daily by Software Engineering Daily

        Software Engineering Daily

        625 Listeners

        Soft Skills Engineering by Jamison Dance and Dave Smith

        Soft Skills Engineering

        269 Listeners

        Super Data Science: ML & AI Podcast with Jon Krohn by Jon Krohn

        Super Data Science: ML & AI Podcast with Jon Krohn

        296 Listeners

        Python Bytes by Michael Kennedy and Brian Okken

        Python Bytes

        213 Listeners

        Data Engineering Podcast by Tobias Macey

        Data Engineering Podcast

        142 Listeners

        Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

        Syntax - Tasty Web Development Treats

        983 Listeners

        DataFramed by DataCamp

        DataFramed

        266 Listeners

        Kubernetes Podcast from Google by Abdel Sghiouar, Kaslin Fields

        Kubernetes Podcast from Google

        181 Listeners

        Practical AI by Practical AI LLC

        Practical AI

        189 Listeners

        The Stack Overflow Podcast by The Stack Overflow Podcast

        The Stack Overflow Podcast

        64 Listeners

        The Pragmatic Engineer by Gergely Orosz

        The Pragmatic Engineer

        52 Listeners