Functional Programming in Python
$19.00
Minimum price
$29.00
Suggested price

Functional Programming in Python

About the Book

Functional Programming in Python

A Practical Guide to Writing Clean and Efficient Code

This book introduces functional programming concepts using Python, helping developers write clearer, more maintainable, and more predictable code.

You'll learn how to:

  • Use core functional tools like map(), filter(), reduce(), and comprehensions
  • Work with immutable data and pure functions
  • Apply modules like functools and itertools effectively
  • Structure programs using a functional approach
  • Improve testability and reduce side effects in your code

Whether you're looking to adopt a functional style for specific parts of your projects or gain a deeper understanding of programming paradigms, this book offers practical examples and explanations tailored to Python programmers.

Functional Programming in Python is ideal for developers with some Python experience who want to write more reliable and modular code.

About the Author

Gábor Szabó
Gábor Szabó

Gabor Szabo has been programming for more than 40 years in a number of languages and in various environments. He used to do DevOps before there was a name for it.

These days he usually helps companies improve their engineering practices by providing training, introducing test automation, CI, CD. Sometimes this includes building internal web sites. Gabor also loves explaining things and provides training to his clients.

He also has a number of websites. Each one using a different technology.

Gabor runs the Code Maven site and a number of its sub-site where he write about lots of different technologies such as Python, Rust, Git, Continuous Integration, etc.

Gabor has been writing Perl since 1995 and teaching it since 2000. He is the author of the Perl Maven site including the Perl Tutorial. He has taught web development with Perl Dancer many time including at Perl Conferences in Europe and USA. Gabor is the chief editor of the Perl Weekly newsletter.

Table of Contents

    • Functional programming in Python
    • Programming Paradigms
    • Functional programming
    • Iterators (Iterables)
      • string
      • list
      • tuple
      • filehandle
      • range
    • range
      • range with 3 parameters
      • range with 2 parameters
      • range with 1 parameter
    • range index and len
    • filehandle index and len
      • len
      • index
    • range with list
    • range vs. list size using getsizeof
    • for loop with transformation
    • map
    • map with list
    • size of map
    • map delaying function call
    • map on many values
    • double with lambda
    • What is lambda in Python?
    • lambda returning tuple
    • map returning tuples
    • lambda with two parameters
    • map for more than one iterable
    • map on uneven lists
    • replace None (for Python 2)
    • map on uneven lists - fixed (for Python 2)
    • map mixed iterators
    • map fetch value from dictionary
    • Exercise: string to length
    • Exercise: row to length
    • Exercise: compare rows
    • Solution: string to length
    • Solution: row to length
    • Solution: compare rows
    • filter in a loop
    • filter
    • filter with lambda
    • filter - map example
    • filter - map in one expression
    • filter a dictionary using dict comprehension
    • Get indices of values
    • reduce
    • reduce empty list
    • reduce with default
    • reduce list of dictionaries
    • zip
    • Combining two lists using zip
    • Creating dictionary from two lists using zip
    • all, any
    • Compare elements of list with scalar
    • List comprehension - double
    • List comprehension - simple expression
    • List generator
    • List comprehension
    • Dict comprehension
    • Lookup table with lambda
    • Read lines without newlines
    • Read key-value pairs
    • Create index-to-value mapping in a dictionary based on a list of values
    • Exercise: min, max, factorial
    • Exercise: Prime numbers
    • Exercise: Many validator functions
    • Exercise: Calculator using lookup table
    • Exercise: parse file
    • Solution: min, max, factorial
    • Solution: Prime numbers
    • Solution: Many validator functions
    • Solution: Calculator using lookup table
    • map with condtion
    • map with lambda
    • map with lambda with condition
    • List comprehension - complex
    • Change list before iteration over map object
    • Replace list before iteration over map object
    • Iterators - with and without Itertools
    • Advantages of iterators and generators
    • The Fibonacci research institute
    • Fibonacci plain
    • Fibonacci copy-paste
    • Iterators Glossary
    • What are iterators and iterables?
    • A file-handle is an iterator
    • range is iterable but it is not an iterator
    • Range with floating point steps
    • Iterator: a counter
    • Using iterator
    • Iterator without temporary variable
    • The type of the iterator
    • Using iterator with next
    • Mixing for and next
    • Iterable which is not an iterator
    • Iterator returning multiple values
    • Range-like iterator
    • Unbound or infinite iterator
    • Unbound iterator Fibonacci
    • Operations on Unbound iterator
    • itertools
    • itertools - count
    • itertools - cycle
    • Exercise: iterators - reimplement the range function
    • Exercise: iterators - cycle
    • Exercise: iterators - alter
    • Exercise: iterators - limit Fibonacci
    • Exercise: iterators - Fibonacci less memory
    • Exercise: read char
    • Exercise: read section
    • Exercise: collect packets
    • Exercise: compare files
    • Solution: iterators - limit Fibonacci
    • Solution: iterators - Fibonacci less memory
    • Solution: read section
    • Solution: compare files
    • Solution: collect packets
    • Generators and Generator Expressions
    • Generators Glossary
    • Iterators vs Generators
    • List comprehension and Generator Expression
    • List comprehension vs Generator Expression - less memory
    • List comprehension vs Generator Expression - lazy evaluation
    • Generator: function with yield - call next
    • Generators - call next
    • Generator with yield
    • Generators - fixed counter
    • Generators - counter
    • Generators - counter with parameter
    • Generators - my_range
    • Fibonacci - generator
    • Infinite series
    • Integers
    • Integers + 3
    • Integers + Integers
    • Filtered Fibonacci
    • The series.py
    • generator - unbound count (with yield)
    • iterator - cycle
    • Exercise: Alternator
    • Exercise: Prime number generator
    • Exercise: generator
    • Exercise: Binary file reader
    • Exercise: File reader with records
    • yield outside of functions
    • Operations on infinite lists
    • Infinite random number generator
    • Infinite random set generator
    • Simple function (before generators)
    • Filtered Fibonacci with ifilter

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub