Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition
- Length: 576 pages
- Edition: 3
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2022-12-30
- ISBN-10: 1803232579
- ISBN-13: 9781803232577
- Sales Rank: #521690 (See Top 100 Books)
Python isn’t all about object-oriented programming. Discover a valuable way of thinking about code design through a function-first approach – and learn when you need to use it. Now with detailed exercises at the end of every chapter!
Purchase of the print or Kindle book includes a free eBook in PDF format.
Key Features
- Learn how, when, and why to adopt functional elements in your projects
- Explore the Python modules essential to functional programming, like itertools and functools
- Revised to cover new features of Python 3.10, exercises at the end of every chapter, and more
Book Description
Not enough developers understand the benefits of functional programming, or even what it is. Author Steven Lott demystifies the approach, teaching you how to improve the way you code in Python and make gains in memory use and performance.
Starting from the fundamentals, this book shows you how to apply functional thinking and techniques in a range of scenarios, with examples centered around data cleaning and exploratory data analysis. You’ll learn how to use generator expressions, list comprehensions, and decorators to your advantage. You don’t have to abandon object-oriented design completely, though – you’ll also see how Python’s native object-orientation is used in conjunction with functional programming techniques.
By the end of this book, you’ll be well versed in the essential functional programming features of Python, and understand why and when functional thinking helps. You’ll also have all the tools you need to pursue any additional functional topics that are not part of the Python language.
What you will learn
- Use Python’s libraries to avoid the complexities of state-changing classes
- Leverage built-in higher-order functions to avoid rewriting common algorithms
- Write generator functions to create lazy processing
- Design and implement decorators for functional composition
- Make use of Python type annotations to describe parameters and results of functions
- Apply functional programming to concurrency and web services
- Explore the PyMonad library for stateful simulations
Who this book is for
The functional paradigm is very useful for programmers working in data science, but any Python developer who wants to create more reliable, succinct, and expressive code will have much to learn from this book.
No prior knowledge of functional programming is required to get started, though Python programming knowledge is assumed. A running Python environment is essential.
Preface Chapter 1: Understanding Functional Programming 1.1 The functional style of programming 1.2 Comparing and contrasting procedural and functional styles 1.3 A classic example of functional programming 1.4 Exploratory data analysis 1.5 Summary 1.6 Exercises Join our community Discord space Chapter 2: Introducing Essential Functional Concepts 2.1 Functions as first-class objects 2.2 Immutable data 2.3 Strict and non-strict evaluation 2.4 Lazy and eager evaluation 2.5 Recursion instead of an explicit loop state 2.6 Functional type systems 2.7 Familiar territory 2.8 Learning some advanced concepts 2.9 Summary 2.10 Exercises Join our community Discord space Chapter 3: Functions, Iterators, and Generators 3.1 Writing pure functions 3.2 Functions as first-class objects 3.3 Using strings 3.4 Using tuples and named tuples 3.5 Using generator expressions 3.6 Cleaning raw data with generator functions 3.7 Applying generators to built-in collections 3.8 Summary 3.9 Exercises Join our community Discord space Chapter 4: Working with Collections 4.1 An overview of function varieties 4.2 Working with iterables 4.3 Using any() and all() as reductions 4.4 Using len() and sum() on collections 4.5 Using zip() to structure and flatten sequences 4.6 Using sorted() and reversed() to change the order 4.7 Using enumerate() to include a sequence number 4.8 Summary 4.9 Exercises Join our community Discord space Chapter 5: Higher-Order Functions 5.1 Using max() and min() to find extrema 5.2 Using the map() function to apply a function to a collection 5.3 Using the filter() function to pass or reject data 5.4 The iter() function with a sentinel value 5.5 Using sorted() to put data in order 5.6 Overview of writing higher-order functions 5.7 Writing higher-order mappings and filters 5.8 Building higher-order functions with callables 5.9 Review of some design patterns 5.10 Summary 5.11 Exercises Join our community Discord space Chapter 6: Recursions and Reductions 6.1 Simple numerical recursions 6.2 Reductions and folding a collection from many items to one 6.3 Group-by reduction from many items to fewer 6.4 Summary 6.5 Exercises Join our community Discord space Chapter 7: Complex Stateless Objects 7.1 Using tuples to collect data 7.2 Using NamedTuple to collect data 7.3 Using frozen dataclasses to collect data 7.4 Complicated object initialization and property computations 7.5 Using pyrsistent to collect data 7.6 Avoiding stateful classes by using families of tuples 7.7 Polymorphism and type pattern matching 7.8 Summary 7.9 Exercises Join our community Discord space Chapter 8: The Itertools Module 8.1 Working with the infinite iterators 8.2 Using the finite iterators 8.3 Cloning iterators with tee() 8.4 The itertools recipes 8.5 Summary 8.6 Exercises Join our community Discord space Chapter 9: Itertools for Combinatorics – Permutations and Combinations 9.1 Enumerating the Cartesian product 9.2 Reducing a product 9.3 Performance improvements 9.4 Permuting a collection of values 9.5 Generating all combinations 9.6 Recipes 9.7 Summary 9.8 Exercises Join our community Discord space Chapter 10: The Functools Module 10.1 Function tools 10.2 Memoizing previous results with cache 10.3 Defining classes with total ordering 10.4 Applying partial arguments with partial() 10.5 Reducing sets of data with the reduce() function 10.6 Handling multiple types with singledispatch 10.7 Summary 10.8 Exercises Join our community Discord space Chapter 11: The Toolz Package 11.1 The itertools star map function 11.2 Reducing with operator module functions 11.3 Using the toolz package 11.4 Summary 11.5 Exercises Chapter 12: Decorator Design Techniques 12.1 Decorators as higher-order functions 12.2 Cross-cutting concerns 12.3 Composite design 12.4 Adding a parameter to a decorator 12.5 Implementing more complex decorators 12.6 Complicated design considerations 12.7 Summary 12.8 Exercises Chapter 13: The PyMonad Library 13.1 Downloading and installing 13.2 Functional composition and currying 13.3 Functors – making everything a function 13.4 Monad bind() function 13.5 Implementing simulation with monads 13.6 Additional PyMonad features 13.7 Summary 13.8 Exercises Join our community Discord space Chapter 14: The Multiprocessing, Threading, and Concurrent.Futures Modules 14.1 Functional programming and concurrency 14.2 What concurrency really means 14.3 Using multiprocessing pools and tasks 14.4 Using a multiprocessing pool for concurrent processing 14.5 Summary 14.6 Exercises Chapter 15: A Functional Approach to Web Services 15.1 The HTTP request-response model 15.2 The WSGI standard 15.3 Defining web services as functions 15.4 Tracking usage 15.5 Summary 15.6 Exercises Join our community Discord space Other Books You Might Enjoy Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.