My Account Log in

1 option

Functional Python Programming, 3rd Edition : Use a Functional Approach to Write Succinct, Expressive, and Efficient Python Code / Steven F. Lott and Ricardo Bánffy.

Ebook Central College Complete Available online

View online
Format:
Book
Author/Creator:
Lott, Steven F., author.
Bánffy, Ricardo, author.
Language:
English
Subjects (All):
Functional programming (Computer science).
Python (Computer program language).
Physical Description:
1 online resource (577 pages)
Edition:
Third edition.
Place of Publication:
Birmingham, England : Packt Publishing Ltd., [2022]
Biography/History:
Lott Steven F. : Steven Lott has been programming since computers were large, expensive, and rare. Working for decades in high tech has given him exposure to a lot of ideas and techniques, some bad, but most are helpful to others. Since the 1990s, Steven has been engaged with Python, crafting an array of indispensable tools and applications. His profound expertise has led him to contribute significantly to Packt Publishing, penning notable titles like "Mastering Object-Oriented, " "The Modern Python Cookbook, " and "Functional Python Programming. " A self-proclaimed technomad, Steven's unconventional lifestyle sees him residing on a boat, often anchored along the vibrant east coast of the US. He tries to live by the words "Don't come home until you have a story. "
Summary:
“Using this book has propelled my efficiency in solving leetcode challenges.” - Discord user, zizu 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 FeaturesLearn how, when, and why to adopt functional elements in your projectsExplore the Python modules essential to functional programming, like itertools and functoolsCover examples relevant to mathematical, statistical, and data analysis domainsBook DescriptionNot 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. If you’re a leetcoder preparing for coding interviews, this book is for you. Starting from the fundamentals, this book shows you how to apply functional thinking and techniques in a range of scenarios, with Python 3.10+ examples focused on mathematical and statistical algorithms, 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 learnUse Python's libraries to avoid the complexities of state-changing classesLeverage built-in higher-order functions to avoid rewriting common algorithmsWrite generator functions to create lazy processingDesign and implement decorators for functional compositionMake use of Python type annotations to describe parameters and results of functionsApply functional programming to concurrency and web servicesExplore the PyMonad library for stateful simulationsWho this book is forThe functional paradigm is very useful for programmers working in data science or preparing for technical interviews, 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.
Contents:
Cover
Copyright
Contributors
Table of Contents
Preface
Chapter 1: Understanding Functional Programming
The functional style of programming
Comparing and contrasting procedural and functional styles
Using the functional paradigm
Using a functional hybrid
The stack of turtles
A classic example of functional programming
Exploratory data analysis
Summary
Exercises
Convert an imperative algorithm to functional code
Convert step-wise computation to functional code
Revise the sqrt() function
Data cleansing steps
(Advanced) Optimize this functional code
Chapter 2: Introducing Essential Functional Concepts
Functions as first-class objects
Pure functions
Higher-order functions
Immutable data
Strict and non-strict evaluation
Lazy and eager evaluation
Recursion instead of an explicit loop state
Functional type systems
Familiar territory
Learning some advanced concepts
Apply map() to a sequence of values
Function vs. lambda design question
Optimize a recursion
Chapter 3: Functions, Iterators, and Generators
Writing pure functions
Using strings
Using tuples and named tuples
Using generator expressions
Exploring the limitations of generators
Combining generator expressions
Cleaning raw data with generator functions
Applying generators to built-in collections
Generators for lists, dicts, and sets
Using stateful mappings
Using the bisect module to create a mapping
Using stateful sets
Rewrite the some_function() function
Alternative Mersenne class definition
Alternative algorithm implementations
Map and filter
Dictionary comprehension
Raw data cleanup
Chapter 4: Working with Collections
An overview of function varieties.
Working with iterables
Parsing an XML file
Parsing a file at a higher level
Pairing up items from a sequence
Using the iter() function explicitly
Extending an iteration
Applying generator expressions to scalar functions
Using any() and all() as reductions
Using len() and sum() on collections
Using sums and counts for statistics
Using zip() to structure and flatten sequences
Unzipping a zipped sequence
Flattening sequences
Structuring flat sequences
Structuring flat sequences - an alternative approach
Using sorted() and reversed() to change the order
Using enumerate() to include a sequence number
Palindromic numbers
Hands of cards
Replace legs() with pairwise()
Chapter 5: Higher-Order Functions
Using max() and min() to find extrema
Using Python lambda forms
Lambdas and the lambda calculus
Using the map() function to apply a function to a collection
Working with lambda forms and map()
Using map() with multiple sequences
Using the filter() function to pass or reject data
Using filter() to identify outliers
The iter() function with a sentinel value
Using sorted() to put data in order
Overview of writing higher-order functions
Writing higher-order mappings and filters
Unwrapping data while mapping
Wrapping additional data while mapping
Flattening data while mapping
Structuring data while filtering
Building higher-order functions with callables
Assuring good functional design
Review of some design patterns
Classification of state
Classification of state, Part II
Optimizing a file parser
Chapter 6: Recursions and Reductions
Simple numerical recursions
Implementing manual tail-call optimization
Leaving recursion in place
Handling difficult tail-call optimization.
Processing collections through recursion
Tail-call optimization for collections
Using the assignment (sometimes called the "walrus") operator in recursions
Reductions and folding a collection from many items to one
Tail-call optimization using deques
Group-by reduction from many items to fewer
Building a mapping with Counter
Building a mapping by sorting
Grouping or partitioning data by key values
Writing more general group-by reductions
Writing higher-order reductions
Writing file parsers
Parsing CSV files
Parsing plain text files with headers
Multiple recursion and caching
Refactor the all_print() function
Classification of state, Part III
Diesel engine data
Chapter 7: Complex Stateless Objects
Using tuples to collect data
Using NamedTuple to collect data
Using frozen dataclasses to collect data
Complicated object initialization and property computations
Using pyrsistent to collect data
Avoiding stateful classes by using families of tuples
Computing Spearman's rank-order correlation
Polymorphism and type pattern matching
Frozen dictionaries
Dictionary-like sequences
Revise the rank_xy() function to use native types
Revise the rank_corr() function
Revise the legs() function to use pyrsistent
Chapter 8: The Itertools Module
Working with the infinite iterators
Counting with count()
Counting with float arguments
Re-iterating a cycle with cycle()
Using cycle() for data sampling
Repeating a single value with repeat()
Using the finite iterators
Assigning numbers with enumerate()
Running totals with accumulate()
Combining iterators with chain()
Partitioning an iterator with groupby()
Merging iterables with zip_longest() and zip().
Creating pairs with pairwise())
Filtering with compress()
Picking subsets with islice()
Stateful filtering with dropwhile() and takewhile()
Two approaches to filtering with filterfalse() and filter()
Applying a function to data via starmap() and map()
Cloning iterators with tee()
The itertools recipes
Optimize the find_first() function
Compare Chapter 4 with the itertools.pairwise() recipe
Compare Chapter 4 with itertools.tee() recipe
Splitting a dataset for training and testing purposes
Rank ordering
Chapter 9: Itertools for Combinatorics - Permutations and Combinations
Enumerating the Cartesian product
Reducing a product
Computing distances
Getting all pixels and all colors
Performance improvements
Rearranging the problem
Combining two transformations
Permuting a collection of values
Generating all combinations
Combinations with replacement
Recipes
Alternative distance computations
Actual domain of pixel color values
Cribbage hand scoring
Chapter 10: The Functools Module
Function tools
Memoizing previous results with cache
Defining classes with total ordering
Applying partial arguments with partial()
Reducing sets of data with the reduce() function
Combining map() and reduce()
Using the reduce() and partial() functions
Using the map() and reduce() functions to sanitize raw data
Using the groupby() and reduce() functions
Avoiding problems with reduce()
Handling multiple types with singledispatch
Compare string.join() and reduce()
Extend the comma_fix() function
Revise the clean_sum() function
Chapter 11: The Toolz Package
The itertools star map function
Reducing with operator module functions
Using the toolz package
Some itertoolz functions.
Some dicttoolz functions
Some functoolz functions
Replace true division with a fraction
Color file parsing
Anscombe's quartet parsing
Waypoint computations
Waypoint geofence
Callable object for the row_counter() function
Chapter 12: Decorator Design Techniques
Decorators as higher-order functions
Using the functools update_wrapper() function
Cross-cutting concerns
Composite design
Preprocessing bad data
Adding a parameter to a decorator
Implementing more complex decorators
Complicated design considerations
Datetime conversions
Optimize a decorator
None-tolerant functions
Logging
Dry-run check
Chapter 13: The PyMonad Library
Downloading and installing
Functional composition and currying
Using curried higher-order functions
Functional composition with PyMonad
Functors - making everything a function
Using the lazy ListMonad() monad
Monad bind() function
Implementing simulation with monads
Additional PyMonad features
Revise the arctangent series
Statistical computations
Data validation
Multiple models
Chapter 14: The Multiprocessing, Threading, and Concurrent.Futures Modules
Functional programming and concurrency
What concurrency really means
The boundary conditions
Sharing resources with process or threads
Where benefits will accrue
Using multiprocessing pools and tasks
Processing many large files
Parsing log files - gathering the rows
Parsing log lines into named tuples
Parsing additional fields of an Access object
Filtering the access details
Analyzing the access details
The complete analysis process
Using a multiprocessing pool for concurrent processing
Using apply() to make a single request.
More complex multiprocessing architectures.
Notes:
Includes index.
Description based on publisher supplied metadata and other sources.
Description based on print version record.
ISBN:
9781803236568
1803236566
OCLC:
1356574044

The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.

Find

Home Release notes

My Account

Shelf Request an item Bookmarks Fines and fees Settings

Guides

Using the Find catalog Using Articles+ Using your account