Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
150 views

Full Download Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition Lott PDF DOCX

efficient

Uploaded by

budrohabbe9s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
150 views

Full Download Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition Lott PDF DOCX

efficient

Uploaded by

budrohabbe9s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Functional Python Programming: Use a functional


approach to write succinct, expressive, and
efficient Python code, 3rd Edition Lott

https://textbookfull.com/product/functional-python-
programming-use-a-functional-approach-to-write-succinct-
expressive-and-efficient-python-code-3rd-edition-lott/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Learn Python Programming A beginner s guide to learning


the fundamentals of Python language to write efficient
high quality code Romano
https://textbookfull.com/product/learn-python-programming-a-beginner-
s-guide-to-learning-the-fundamentals-of-python-language-to-write-
efficient-high-quality-code-romano/
textboxfull.com

Functional Python Programming Discover the power of


functional programming generator functions lazy evaluation
the built in itertools library and monads 2nd Edition
Steven F. Lott
https://textbookfull.com/product/functional-python-programming-
discover-the-power-of-functional-programming-generator-functions-lazy-
evaluation-the-built-in-itertools-library-and-monads-2nd-edition-
steven-f-lott/
textboxfull.com

Functional Programming in C#: How to write better C# code


1st Edition Enrico Buonanno

https://textbookfull.com/product/functional-programming-in-c-how-to-
write-better-c-code-1st-edition-enrico-buonanno/

textboxfull.com
Function Python programming discover the power of
functional programming generator functions lazy evaluation
the built in itertools library and monads Second Edition
Lott
https://textbookfull.com/product/function-python-programming-discover-
the-power-of-functional-programming-generator-functions-lazy-
evaluation-the-built-in-itertools-library-and-monads-second-edition-
lott/
textboxfull.com

A Functional Approach to Java: Augmenting Object-Oriented


Java Code with Functional Principles 1st Edition Ben
Weidig
https://textbookfull.com/product/a-functional-approach-to-java-
augmenting-object-oriented-java-code-with-functional-principles-1st-
edition-ben-weidig/
textboxfull.com

Python Projects for Beginners: A Ten-Week Bootcamp


Approach to Python Programming Milliken

https://textbookfull.com/product/python-projects-for-beginners-a-ten-
week-bootcamp-approach-to-python-programming-milliken/

textboxfull.com

Teach Your Kids to Code A Parent Friendly Guide to Python


Programming 1st Edition Bryson Payne

https://textbookfull.com/product/teach-your-kids-to-code-a-parent-
friendly-guide-to-python-programming-1st-edition-bryson-payne/

textboxfull.com

Effective Python 90 Specific Ways to Write Better Python


2nd Edition Brett Slatkin

https://textbookfull.com/product/effective-python-90-specific-ways-to-
write-better-python-2nd-edition-brett-slatkin/

textboxfull.com
Functional Python
Programming
Third Edition

Use a functional approach to write succinct,


expressive, and efficient Python code

Steven F. Lott

BIRMINGHAM—MUMBAI
“Python” and the Python logo are trademarks of the Python Software Foundation.
Functional Python Programming
Third Edition
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held
liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.

Senior Publishing Product Manager: Denim Pinto


Acquisition Editor – Peer Reviews: Gaurav Gavas
Project Editor: Parvathy Nair
Development Editor: Lucy Wan
Copy Editor: Safis Editing
Technical Editor: Karan Sonawane
Indexer: Hemangini Bari
Proofreader: Safis Editing
Presentation Designer: Sandip Tadge

First published: January 2015


Second edition: April 2018
Third edition: December 2022

Production reference: 1221222


Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80323-257-7
www.packt.com
Foreword

Python is an incredibly versatile language that offers a lot of perks for just about every
group. For the object-oriented programming fans, it has classes and inheritance. When
we talk about functional programming, it has functions as a first-class type, higher-order
functions such as map and reduce, and a handy syntax for comprehensions and generators.
Perhaps best of all, it doesn’t force any of those on the user – it’s still totally OK to write a
script in Python without a single class or function and not feel guilty about it.

Thinking in terms of functional programming, having in mind the goals of minimizing state
and side effects, writing pure functions, reducing intermediary data, and what depends on
what else will also allow you to see your code under a new light. It’ll also allow you to
write more compact, performant, testable, and maintainable code, where instead of writing
a program to solve your problem, you “write the language up”, adding new functions to
it until expressing the solution you designed is simple and straightforward. This is an
extremely powerful mind shift – and an exercise worth doing. It’s a bit like learning a
new language, such as Lisp or Forth (or German, or Irish), but without having to leave the
comfort of your Python environment.

Not being a pure functional language has its costs, however. Python lacks many features
functional languages can use to provide better memory efficiency and speed. Python’s
strongest point remains its accessibility – you can fire up your Python interpreter and
start playing with the examples in this book right away. This interactive approach allows
exploratory programming, where you test ideas easily, and only later need to incorporate
them into a more complex program (or not – like I said, it’s totally OK to write a simple
script).

This book is intended for people already familiar with Python. You don’t need to know
much about functional programming – the book will guide you through many common
approaches, techniques, and patterns used in functional programming and how they can
be best expressed in Python. Think of this book as an introduction – it’ll give you the basic
tools to see, think, and express your ideas in functional terms using Python.

Ricardo Bánffy

Software Engineer, Architect, Evangelist, and Passionate Pythonista


Contributors

About the author


Steven F. 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 are bad, but most are useful and helpful to others.

Steven has been working with Python since the ‘90s, building a variety of tools and
applications. He’s written a number of titles for Packt Publishing, include Mastering
Object-Oriented Python, Modern Python Cookbook, and Functional Python Programming.

He’s a technomad, and lives on a boat that’s usually located on the east coast of the US. He
tries to live by the words, “Don’t come home until you have a story.”
About the reviewers
Alex Martelli is a Fellow of the Python Software Foundation, a winner of the Frank
Willison Memorial Award for contributions to the Python community, and a top-page
reputation hog on Stack Overflow. He spent 8 years with IBM Research, then 13 years
at Think3 Inc., followed by 4 years as a consultant, and lately 17 years at Google. He
has taught programming languages, development methods, and numerical computing at
Ferrara University and other venues.

Books he has authored or co-authored include two editions of Python Cookbook, four
editions of Python in a Nutshell, and a chapter in Beautiful Teams. Dozens of his interviews
and tech talks at conferences are available on YouTube. Alex’s proudest achievement are
the articles that appeared in Bridge World (January and February 2000), which were hailed
as giant steps towards solving issues that had haunted contract bridge theoreticians for
decades, and still get quoted in current bridge-theoretical literature.

Tiago Antao has a BEng in Informatics and a PhD in Life Sciences. He works in the
Big Data space, analyzing very large datasets and implementing complex data processing
algorithms. He leverages Python with all its libraries to carry out scientific computing and
data engineering tasks. He also uses low-level programming languages like C, C++, and
Rust to optimize critical parts of algorithms. Tiago develops on an infrastructure based on
AWS, but has used on-premises computing and scientific clusters for most of his career.

While he currently works in industry, he also has exposure to the academic side of scientific
computing, with two data analysis postdocs at the universities of Cambridge and Oxford,
and a research scientist position at the University of Montana, where he set up, from
scratch, the scientific computing infrastructure for the analysis of biological data.

He is one of the co-authors of Biopython, a major bioinformatics package written in Python.


He wrote Bioinformatics with Python Cookbook, which is on its third edition. He has also
authored and co-authored many high-impact scientific articles in the field of bioinformatics.
Join our community Discord space
Join our Python Discord workspace to discuss and know more about the book:
https://packt.link/dHrHU
Table of Contents

Preface xxi

Chapter 1: Understanding Functional Programming 1

The functional style of programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3


Comparing and contrasting procedural and functional styles . . . . . . . . . . . . . . . . . . . . . 4
Using the functional paradigm • 5
Using a functional hybrid • 8
The stack of turtles • 9
A classic example of functional programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Exploratory data analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Convert an imperative algorithm to functional code • 18
Convert step-wise computation to functional code • 18
Revise the sqrt() function • 20
Data cleansing steps • 20
(Advanced) Optimize this functional code • 23

Chapter 2: Introducing Essential Functional Concepts 25

Functions as first-class objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26


Pure functions • 27
Higher-order functions • 29
Immutable data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Strict and non-strict evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Lazy and eager evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Recursion instead of an explicit loop state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Functional type systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Familiar territory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Learning some advanced concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Apply map() to a sequence of values • 44
Function vs. lambda design question • 45
Optimize a recursion • 45

Chapter 3: Functions, Iterators, and Generators 47

Writing pure functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48


Functions as first-class objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Using strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Using tuples and named tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Using generator expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exploring the limitations of generators • 63
Combining generator expressions • 65
Cleaning raw data with generator functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Applying generators to built-in collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Generators for lists, dicts, and sets • 69
Using stateful mappings • 73
Using the bisect module to create a mapping • 76
Using stateful sets • 78
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Rewrite the some_function() function • 79
Alternative Mersenne class definition • 80
Alternative algorithm implementations • 81
Map and filter • 82
Dictionary comprehension • 82
Raw data cleanup • 82

Chapter 4: Working with Collections 85

An overview of function varieties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86


Working with iterables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Parsing an XML file • 89
Parsing a file at a higher level • 92
Pairing up items from a sequence • 95
Using the iter() function explicitly • 98
Extending an iteration • 100
Applying generator expressions to scalar functions • 104
Using any() and all() as reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Using len() and sum() on collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Using sums and counts for statistics • 111
Using zip() to structure and flatten sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Unzipping a zipped sequence • 117
Flattening sequences • 118
Structuring flat sequences • 120
Structuring flat sequences – an alternative approach • 124
Using sorted() and reversed() to change the order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Using enumerate() to include a sequence number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Palindromic numbers • 129
Hands of cards • 130
Replace legs() with pairwise() • 131
Expand legs() to include processing • 132

Chapter 5: Higher-Order Functions 133

Using max() and min() to find extrema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134


Using Python lambda forms • 138
Lambdas and the lambda calculus • 140
Using the map() function to apply a function to a collection . . . . . . . . . . . . . . . . . . . . . . 141
Working with lambda forms and map() • 143
Using map() with multiple sequences • 144
Using the filter() function to pass or reject data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Using filter() to identify outliers • 149
The iter() function with a sentinel value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Using sorted() to put data in order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Overview of writing higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Writing higher-order mappings and filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Unwrapping data while mapping • 156
Wrapping additional data while mapping • 159
Flattening data while mapping • 161
Structuring data while filtering • 164
Building higher-order functions with callables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Assuring good functional design • 168
Review of some design patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Classification of state • 173
Classification of state, Part II • 174
Optimizing a file parser • 175
Chapter 6: Recursions and Reductions 177

Simple numerical recursions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178


Implementing manual tail-call optimization • 180
Leaving recursion in place • 181
Handling difficult tail-call optimization • 182
Processing collections through recursion • 184
Tail-call optimization for collections • 185
Using the assignment (sometimes called the “walrus”) operator in recursions • 187
Reductions and folding a collection from many items to one . . . . . . . . . . . . . . . . . . . . . . 188
Tail-call optimization using deques • 190
Group-by reduction from many items to fewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Building a mapping with Counter • 195
Building a mapping by sorting • 196
Grouping or partitioning data by key values • 198
Writing more general group-by reductions • 203
Writing higher-order reductions • 205
Writing file parsers • 207
Parsing CSV files • 211
Parsing plain text files with headers • 214
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Multiple recursion and caching • 219
Refactor the all_print() function • 219
Parsing CSV files • 219
Classification of state, Part III • 220
Diesel engine data • 220

Chapter 7: Complex Stateless Objects 223

Using tuples to collect data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224


Using NamedTuple to collect data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Using frozen dataclasses to collect data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Complicated object initialization and property computations . . . . . . . . . . . . . . . . . . . . . 237
Using pyrsistent to collect data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Avoiding stateful classes by using families of tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Computing Spearman’s rank-order correlation • 252
Polymorphism and type pattern matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Frozen dictionaries • 263
Dictionary-like sequences • 264
Revise the rank_xy() function to use native types • 265
Revise the rank_corr() function • 265
Revise the legs() function to use pyrsistent • 265

Chapter 8: The Itertools Module 267

Working with the infinite iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269


Counting with count() • 269
Counting with float arguments • 271
Re-iterating a cycle with cycle() • 275
Using cycle() for data sampling • 276
Repeating a single value with repeat() • 278
Using the finite iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Assigning numbers with enumerate() • 281
Running totals with accumulate() • 284
Combining iterators with chain() • 286
Partitioning an iterator with groupby() • 287
Merging iterables with zip_longest() and zip() • 290
Creating pairs with pairwise()) • 290
Filtering with compress() • 291
Picking subsets with islice() • 293
Stateful filtering with dropwhile() and takewhile() • 295
Two approaches to filtering with filterfalse() and filter() • 297
Applying a function to data via starmap() and map() • 298
Cloning iterators with tee() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
The itertools recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Optimize the find_first() function • 306
Compare Chapter 4 with the itertools.pairwise() recipe • 306
Compare Chapter 4 with itertools.tee() recipe • 307
Splitting a dataset for training and testing purposes • 307
Rank ordering • 307

Chapter 9: Itertools for Combinatorics – Permutations and Combina-


tions 309

Enumerating the Cartesian product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310


Reducing a product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Computing distances • 314
Getting all pixels and all colors • 318
Performance improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Rearranging the problem • 323
Combining two transformations • 324
Permuting a collection of values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Generating all combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Combinations with replacement • 333
Recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Alternative distance computations • 336
Actual domain of pixel color values • 338
Cribbage hand scoring • 339

Chapter 10: The Functools Module 343

Function tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344


Memoizing previous results with cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Defining classes with total ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Applying partial arguments with partial() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Reducing sets of data with the reduce() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Combining map() and reduce() • 356
Using the reduce() and partial() functions • 358
Using the map() and reduce() functions to sanitize raw data • 360
Using the groupby() and reduce() functions • 362
Avoiding problems with reduce() • 366
Handling multiple types with singledispatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Compare string.join() and reduce() • 370
Extend the comma_fix() function • 370
Revise the clean_sum() function • 371

Chapter 11: The Toolz Package 373

The itertools star map function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374


Reducing with operator module functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Using the toolz package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Some itertoolz functions • 379
Some dicttoolz functions • 385
Some functoolz functions • 386
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Replace true division with a fraction • 391
Color file parsing • 391
Anscombe’s quartet parsing • 392
Waypoint computations • 393
Waypoint geofence • 393
Callable object for the row_counter() function • 394

Chapter 12: Decorator Design Techniques 397

Decorators as higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398


Using the functools update_wrapper() function • 403
Cross-cutting concerns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Composite design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Preprocessing bad data • 407
Adding a parameter to a decorator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Implementing more complex decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Complicated design considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Datetime conversions • 421
Optimize a decorator • 423
None-tolerant functions • 423
Logging • 424
Dry-run check • 425

Chapter 13: The PyMonad Library 427

Downloading and installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428


Functional composition and currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Using curried higher-order functions • 431
Functional composition with PyMonad • 432
Functors – making everything a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Using the lazy ListMonad() monad • 436
Monad bind() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Implementing simulation with monads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Additional PyMonad features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Revise the arctangent series • 449
Statistical computations • 450
Data validation • 450
Multiple models • 451

Chapter 14: The Multiprocessing, Threading, and Concurrent.Futures


Modules 453

Functional programming and concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454


What concurrency really means . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
The boundary conditions • 455
Sharing resources with process or threads • 456
Where benefits will accrue • 457
Using multiprocessing pools and tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Processing many large files • 460
Parsing log files – gathering the rows • 462
Parsing log lines into named tuples • 463
Parsing additional fields of an Access object • 467
Filtering the access details • 471
Analyzing the access details • 472
The complete analysis process • 473
Using a multiprocessing pool for concurrent processing . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Using apply() to make a single request • 478
More complex multiprocessing architectures • 479
Using the concurrent.futures module • 479
Using concurrent.futures thread pools • 480
Using the threading and queue modules • 481
Using async functions • 482
Designing concurrent processing • 483
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Lazy parsing • 487
Filter access path details • 488
Add @cache decorators • 489
Create sample data • 489
Change the pipeline structure • 490

Chapter 15: A Functional Approach to Web Services 491

The HTTP request-response model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492


Injecting state through cookies • 495
Considering a server with a functional design • 496
Looking more deeply into the functional view • 497
Nesting the services • 498
The WSGI standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Raising exceptions during WSGI processing • 503
Pragmatic web applications • 505
Defining web services as functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Flask application processing • 508
The data access tier • 513
Applying a filter • 515
Serializing the results • 516
Serializing data with JSON or CSV formats • 518
Serializing data with XML and HTML • 519
Tracking usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
WSGI application: welcome • 524
WSGI application: demo • 524
Serializing data with XML • 525
Serializing data with HTML • 525

Other Books You Might Enjoy 52

Index 53
Preface

Functional programming offers a variety of techniques for creating succinct and expressive
software. While Python is not a purely functional programming language, we can do a
great deal of functional programming in Python.

Python has a core set of functional programming features. This lets us borrow many design
patterns and techniques from other functional languages. These borrowed concepts can
lead us to create elegant programs. Python’s generator expressions, in particular, negate
the need to create large in-memory data structures, leading to programs that may execute
more quickly because they use fewer resources.

We can’t easily create purely functional programs in Python. Python lacks a number of
features that would be required for this. We don’t have unlimited recursion, for example,
we don’t have lazy evaluation of all expressions, and we don’t have an optimizing compiler.

There are several key features of functional programming languages that are available
in Python. One of the most important ones is the idea of functions being first-class ob-
jects. Python also offers a number of higher-order functions. The built-in map(), filter(),
and functools.reduce() functions are widely used in this role, and less obvious are
functions such as sorted(), min(), and max().

In some cases, a functional approach to a problem will also lead to extremely high-
performance algorithms. Python makes it too easy to create large intermediate data
structures, tying up memory (and processor time). With functional programming de-
sign patterns, we can often replace large lists with generator expressions that are equally
expressive but take up much less memory and run much more quickly.
xxii Preface

We’ll look at the core features of functional programming from a Python point of view.
Our objective is to borrow good ideas from functional programming languages and use
those ideas to create expressive and succinct applications in Python.

Who this book is for


This book is for more experienced programmers who want to create succinct, expressive
Python programs by borrowing techniques and design patterns from functional program-
ming languages. Some algorithms can be expressed elegantly in a functional style; we
can—and should—adapt this to make Python programs more readable and maintainable.

This is not intended as a tutorial on Python. This book assumes some familiarity with the
language and the standard library. For a foundational introduction to Python, consider
Learn Python Programming, Third Edition: https://www.packtpub.com/product/learn-p
ython-programming-third-edition/9781801815093.

While we cover the foundations of functional programming, this is not a complete review of
the various kinds of functional programming techniques. Having an exposure to functional
programming in another language can be helpful.

What this book covers


We can decompose this book into two general kinds of topics:

• Essentials of functional programming in Python. This is the content of Chapters 1


through 7.

• Library modules to help create functional programs. This is the subject of the
remaining chapters of the book. Chapter 12 includes both fundamental language and
library topics.

Chapter 1, Understanding Functional Programming, introduces some of the techniques that


characterize functional programming. We’ll identify some of the ways to map those features
to Python. We’ll also address some ways that the benefits of functional programming accrue
when we use these design patterns to build Python applications.
Preface xxiii

Chapter 2, Introducing Essential Functional Concepts, delves into central features of the
functional programming paradigm. We’ll look at each in some detail to see how they’re
implemented in Python. We’ll also point out some features of functional languages that
don’t apply well to Python. In particular, many functional languages have complex type-
matching rules required to support compiling and optimizing.

Chapter 3, Functions, Iterators, and Generators, will show how to leverage immutable Python
objects, and how generator expressions adapt functional programming concepts to the
Python language. We’ll look at some of the built-in Python collections and how we can
leverage them without departing too far from functional programming concepts.

Chapter 4, Working with Collections, shows how you can use a number of built-in Python
functions to operate on collections of data. This chapter will focus on a number of relatively
simple functions, such as any() and all(), which reduce a collection of values to a single
result.

Chapter 5, Higher-Order Functions, examines the commonly used higher-order functions


such as map() and filter(). It also shows a number of other higher-order functions as
well as how we can create our own functions that work with functions or return functions.

Chapter 6, Recursions and Reductions, teaches how to design an algorithm using recursion
and then optimize it into a high-performance for statement. We’ll also look at some other
reductions that are widely used, including collections.Counter().

Chapter 7, Complex Stateless Objects, showcases a number of ways that we can use immutable
tuples, typing.NamedTuple, and the frozen @dataclass instead of stateful objects. We’ll
also look at the pyrsistent module as a way to create immutable objects. Immutable
objects have a simpler interface than stateful objects: we never have to worry about
abusing an attribute and setting an object into some inconsistent or invalid state.

Chapter 8, The Itertools Module, examines a number of functions in the itertools standard
library module. This collection of functions simplifies writing programs that deal with
collections or generator functions.
xxiv Preface

Chapter 9, Itertools for Combinatorics – Permutations and Combinations, covers the combina-
toric functions in the itertools module. These functions are more specialized than those
in the previous chapter. This chapter includes some examples that illustrate ill-considered
use of these functions and the consequences of combinatoric explosion.

Chapter 10, The Functools Module, focuses on how to use some of the functions in the
functools module for functional programming. A few functions in this module are more
appropriate for building decorators, and they are left for Chapter 12, Decorator Design
Techniques.

Chapter 11, The Toolz Package, covers the toolz package, a number of closely related
modules that help us write functional programs in Python. The toolz modules parallel
the built-in itertools and functools modules, providing alternatives that are often more
sophisticated and make better use of curried functions.

Chapter 12, Decorator Design Techniques, covers how we can look at a decorator as a way
to build a composite function. While there is considerable flexibility here, there are also
some conceptual limitations: we’ll look at ways that overly complex decorators can become
confusing rather than helpful.

Chapter 13, The PyMonad Library, examines some of the features of the PyMonad library.
This provides some additional functional programming features. It also provides a way to
learn more about monads. In some functional languages, monads are an important way to
force a particular order for operations that might get optimized into an undesirable order.
Since Python already has strict ordering of expressions and statements, the monad feature
is more instructive than practical.

Chapter 14, The Multiprocessing, Threading, and Concurrent.Futures Modules, points out
an important consequence of good functional design: we can distribute the processing
workload. Using immutable objects means that we can’t corrupt an object because of poorly
synchronized write operations.

Chapter 15, A Functional Approach to Web Services, shows how we can think of web services
as a nested collection of functions that transform a request into a reply. We’ll see ways to
Preface xxv

leverage functional programming concepts for building responsive, dynamic web content.

Chapter 16, A Chi-Squared Case Study, is a bonus, online-only case study applying a number
of functional programming techniques to a specific exploratory data analysis problem. We
will apply a 𝜒 2 statistical test to some complex data to see if the results show ordinary
variability, or if they are an indication of something that requires deeper analysis. You can
find the case study here: https://github.com/PacktPublishing/Functional-Python-P
rogramming-3rd-Edition/blob/main/Bonus_Content/Chapter_16.pdf.

To get the most out of this book


This book presumes some familiarity with Python 3 and general concepts of application
development. We won’t look deeply at subtle or complex features of Python; we’ll avoid
much consideration of the internals of the language.

Some of the examples use exploratory data analysis (EDA) as a problem domain to show
the value of functional programming. Some familiarity with basic probability and statistics
will help with this. There are only a few examples that move into more serious data science.

Python 3.10 is required. The examples have also been tested with Python 3.11, and work
correctly. For data science purposes, it’s often helpful to start with the conda tool to create
and manage virtual environments. It’s not required, however, and readers should be able
to use any available Python.

Additional packages are generally installed with pip. The command looks like this:

% python -m pip install toolz pymonad pyrsistent beautifulsoup4

Complete the exercises


Each chapter includes a number of exercises that help the reader apply the concepts in the
chapter to real code. Most of the exercises are based on code available from the book’s
repository on GitHub: https://github.com/PacktPublishing/Functional-Python-Pro
gramming-3rd-Edition.
xxvi Preface

In some cases, the reader will notice that the code provided on GitHub includes partial
solutions to some of the exercises. These serve as hints, allowing the reader to explore
alternative solutions.

In many cases, exercises will need unit test cases to confirm they actually solve the problem.
These are often identical to the unit test cases already provided in the GitHub repository.
The reader should replace the book’s example function name with their own solution to
confirm that it works.

In some cases, the exercises suggest writing a response document to compare and contrast
multiple solutions. It helps to find a mentor or expert who can help the reader by reviewing
these small documents for clarity and completeness. A good comparison between design
approaches will include performance measurements using the timeit module to show the
performance advantages of one design over another.

Download the example code files


The code bundle for the book is hosted on GitHub at https://github.com/PacktPublis
hing/Functional-Python-Programming-3rd-Edition. We also have other code bundles
from our rich catalog of books and videos available at https://github.com/PacktPublis
hing/. Check them out!

Download the color images


We also provide a PDF file that has color images of the screenshots/diagrams used in this
book. You can download it here: https://packt.link/OV1CB.

Conventions used
There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in the text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example:
“Python has other statements, such as global or nonlocal, which modify the rules for
variables in a particular namespace.”
Preface xxvii

Bold: Indicates a new term, an important word, or words you see on the screen, such as in
menus or dialog boxes. For example: “The base case states that the sum of a zero-length
sequence is 0. The recursive case states that the sum of a sequence is the first value plus
the sum of the rest of the sequence.”

A block of code is set as follows:

print("Hello, World!")

Any command-line input or output is written as follows:

% conda create -n functional3 python=3.10

Warnings or important notes appear like this.

Tips and tricks appear like this.

Get in touch
Feedback from our readers is always welcome.

General feedback: Email feedback@packtpub.com, and mention the book’s title in the
subject of your message. If you have questions about any aspect of this book, please email
us at questions@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book we would be grateful if you would
report this to us. Please visit https://subscription.packtpub.com/help, click on the
Submit Errata button, search for your book, and enter the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet,
xxviii Preface

we would be grateful if you would provide us with the location address or website name.
Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have ex-
pertise in and you are interested in either writing or contributing to a book, please visit
http://authors.packtpub.com.

Share your thoughts


Once you’ve read Functional Python Programming, Third Edition, we’d love to hear your
thoughts! Scan the QR code below to go straight to the Amazon review page for this book
and share your feedback.

https://packt.link/r/1803232579

Your review is important to us and the tech community and will help us make sure we’re
delivering excellent quality content.
Random documents with unrelated
content Scribd suggests to you:
From the foregoing calculation, the quantity of rubble masonry is 3,209.2
cu. ft. Taking 25 cu. ft. to 1 perch, 3,209.2 ÷ 25 = 128.4 perches, which at
$5.23 per perch makes the total cost of rubble masonry $671.53.

Ashlar[9]

Square
Feet
Quantities
Facing for cellar walls, 79' 10" × 2' 2" 173.0
Porch piers, 29' 6" × 1' 6" 43.9
Total ashlar 216.9

Cost
The estimated cost of ashlar is based on the following analysis of the cost
of 1 square foot of ashlar:
Cost of stone, bluestone facing $.40
Hauling stone .03
Mortar .01
Labor, estimating 64 square feet per day of 8 hours,
for two masons and one laborer:
Two masons, at $3.20 per day .10
One laborer at $2 per day .03
Cost per square foot $.57

Summary
From the foregoing quantities, the ashlar amounts to 216.9 square feet,
which, at 57 cents per square foot, will make the total cost of ashlar $123.63.

Cut Stone

Cost
Per Total
Foot Cost
Quantities and Cost
Base, or ground sill, extending around
porches (except under stone steps) and
along exposed main walls, 172 ft., 5" × 11"
and 5" × 13" dressed and chamfered sandstone $1.00 $172.00
Cost
Per Total
Foot Cost
Water-table, extending around main walls, 181 ft. 2 in.,
6" × 10" dressed and chamfered sandstone .85 153.99
Lintel course, extending over brick walls,
125 ft., 6" × 10" dressed sandstone .85 106.25
Twelve dressed sandstone window sills, cut
with lug and drip, 55¾ ft., 5" × 8" .65 36.24
Cut-stone jambs and lintel for main door,
21½ ft., 10" × 12", sandstone 1.75 37.63
One front door sill, 5¾ ft., 6" × 10", sandstone 1.10 6.33
Coping on area walls, 9 ft., 3" × 16", sandstone .60 5.40
Front and side porch steps, 59 ft., 8" × 12",
8" × 12", dressed sandstone 1.25 73.75
Eight bluestone steps for cellar,
outside entrance, 4' × 12" × 2" .35 11.20
Bluestone lintel for kitchen fireplace, 6' × 12" × 6" 1.20 7.20
Cut stone for main chimney 25.00
Cost to set cut stone, 20 per cent. 127.00
Total cost of cut stone $761.99

Concrete Footings and Floor

Cubic
Quantities
Yard
Footings, as per Excavation for Wall Footings,
535.9 cu. ft. ÷ 27 19.8
Square Square
Feet Yard
Concrete floor:
Area of cellar excavation 1,740.0
Deduct area of footings 643.3
1,096.7
Add for 6-inch strip over inner projection
of wall footings, 165' × 6" 82.5
Add for projection on both sides of interior
walls, 126' × 6" 63.0
Add for projection over chimney footing,
33' × 6" 16.5
Total area of concrete floor 1,258.7 = 139.9

Cost
The estimate for concrete footings is based on the analyses of costs given
in Estimating and Calculating Quantities, Part 1, and is $5.10 per cubic yard for
a 1-3-5 mixture.
The estimate for the concrete floor is arrived at as follows:
The concrete will be a 1-3-6 mixture. According to Estimating
and Calculating Quantities, Part 1, this mixture costs $4.92 per
cubic yard. According to the same section, 25 cents must be
added to this cost for extra labor, bringing the total up to $5.17
per cubic yard. If the concrete floor is 4 inches thick, the cost
per square yard will be ⁴/₃₆ × 5.17 = 57 cents, approximately.
The top coat, according to Estimating and Calculating
Quantities, Part 1, is 40 cents. Therefore, the total cost of the
concrete floor per square yard is 57 + 40 = 97 cents.
Summary
Footing concrete, as per foregoing figures,
19.8 cu. yd. at $5.10 per cubic yard $100.98
Concrete floor, 139.9 sq. yd.
at 97 cents per square yard 135.70
Total cost of concrete $236.68

Recapitulation of Cost of Stonework


Rubble masonry $ 671.53
Ashlar masonry 123.63
Cut stone 761.99
Concrete footings and floor 236.68
Total cost of stonework $1,793.83

BRICKWORK
4. In estimating the brickwork, openings have been deducted, thus
practically giving “kiln count,” so that the analyses of prices given heretofore
will apply. If openings had not been deducted, the prices would be 15 per cent.
lower.

Pressed Brick
No .
Quantities
Brick
Facing exterior walls, same length as stone
lintel course, 125' × 8' = 1,000 sq. ft. at
7½ bricks per square foot 7,500

Square No.
Deduct for Openings:
Feet Brick
Nine windows, total width 32' X 6' 6" high 208.0
Two casement windows, total width
7' 4" × 8' high 58.7
One lavatory window, total width
2' X 6" × 5' 6" 13.8
Main door, 5' 5" × 8' 9" 47.4
Total deductions 327.9
327.9 × 7½ = 2,459
Number of brick 5,041
Add 5 per cent. for waste 252
Total pressed brick 5,293

Cost
The cost of pressed brickwork is based on the analysis given in Estimating
and Calculating Quantities, Part 1, and is $53.71 per thousand.
Summary
From the preceding estimate of quantities, the
number of pressed brick laid is 5,041, which,
at $53.71 per M, will cost $270.75
Pressed brick, not laid, 252, at $30 per M 7.56
Total cost of pressed brickwork $278.31

Common Brick

No .
Quantities
Brick
Backing exterior pressed-brick walls, 8½ in. thick,
5,041 × 2 = 10,082
Backing behind lintel course,
9" X 125' × 8" at 15 brick per sq. ft. 1,406
Interior cellar walls, 28' 4" × 8' = 226.7 sq. ft.
(17-inch wall) at 30 brick per square foot 6,801
Deduct for three openings, 12' 3" total width
× 6' 6" height = 79.6 sq. ft. at 30 brick per square foot 2,388 4,413
Interior wall, 8½" thick, 43' 9" × 8', 350 sq. ft.
at 15 brick per square foot 5,250
Chimney, principal (flues figured solid), approximately
920 cu. ft., at 22½ brick per cubic foot 20,700
Chimney, rear, approximately 245 cu. ft.,
at 22½ brick per cubic foot 5,513
Trap pits, 46 sq. ft., at 7½ brick per square foot 345
46,303
Add 5 per cent. for waste 2,315
Total common brick 48,618

Cost
The cost of the common brickwork is based on the analysis given in
Estimating and Calculating Quantities, Part 1, and is $16.68 per thousand for
lime-cement mortar.
Summary
According to the estimate of quantities,
the number of common brick laid is 46,303,
which, at $16.68, will cost $ 772.33
Common bricks, not laid, 2,315, at $8 18.52
Molded brick and terra-cotta cap for rear chimney 10.00
Total cost of common brickwork $ 800.85

Recapitulation of Cost of Brickwork


Pressed brickwork $ 278.31
Common brickwork 800.85
Total cost of brickwork $1,079.16

CARPENTRY
5. In estimating carpentry work, it is advisable to make a tabulated list of
the various sizes of joists, rafters, etc., giving the number and dimensions of
each size. In this way, any error in calculation or change in price can be
corrected with little difficulty.
As house-framing timbers and boards are sold at the yards in even lengths,
as 10 feet, 12 feet, 14 feet, etc., uneven, or odd, measurements must be
figured in even lengths from which they can be cut. Thus, if a stick 14 feet 7
inches in length is required, a 16-foot stick must be ordered.
Usually, the price per thousand feet, board measure, increases as longer
sticks are used, although the practice varies in different localities. For example,
in most localities hemlock timber in 10-, 12-, or 14-foot lengths is all one price
per thousand, but a thousand feet, board measure, of 16-foot lengths costs
more, and 18-foot lengths is still more expensive. The price of yellow pine,
spruce, fir, etc. is usually constant up to 20-foot lengths, but from that length
on the prices increase. The price of white-pine boards in most localities
increases with their width. The hardwoods can be usually obtained in any
reasonable length, the price increasing with the quality of the lumber more
than with the length of the stick.
It can thus be seen that in house framing it is usually cheaper to use short
sticks than long ones. However, for long members, a long stick is cheaper,
because the extra cost that would be incurred in splicing two short sticks would
more than offset the cheapness of the material. Of course, when very long
sticks are required, say sticks 30 feet or more in length, a splice is cheaper,
owing to the difficulty of obtaining them and their very excessive price.
No set rules can be laid down as to what size timber should be ordered,
and every architect and builder should be governed by the prices in the locality
where the house is to be put up.

Floor Framing,
First Story

Linear Feet
Quantities
Feet B. M.
Joists, 3" × 10"; 2½ ft. B. M., per lin. ft.:
6 pieces, each 14' 6", order 16' 96
2 pieces, each 15' 3", order 16' 32
1 piece, 16' 3", order 18' 18
5 pieces, each 17' 6", order 18' 90
1 piece, 12' 6", order 14' 14
6 pieces, each 11' 0", order 12' 72
1 piece, 9' 6", order 10' 10
18 pieces, each 14', order 14' 252
1 piece, 11' 6", order 12' 12
3 pieces, each 10' 6", order 12' 36
1 piece, 9' 4", order 10' 10
6 pieces, each 24', order 24' 144
1 piece, 11' 4", order 12' 12
2 pieces, each 20' 6", order 22' 44
6 pieces, each 20', order 20' 120
4 pieces, each 21', order 22' 88
2 pieces, each 7', cut out of 14' 14
2 pieces, each 13', order 14' 28
1 piece, 10', order 10' 10
Total 1,102 2,755

Floor Framing,
Second Story

Linear Feet
Quantities
Feet B. M.
Girder, 6" × 12"; 6 ft. B. M., per lin. ft.:
1 piece, 8' 9", order 10' 10 60
Joists, 2" × 10"; 1⅔ft. B. M., per lin. ft.:
15 pieces, each 14', order 14' 210
2 pieces, each 15' 6", order 16' 32
5 pieces, each 17', order 18' 90
3 pieces, each 15', order 16' 48
14 pieces, each 16', order 16' 224
2 pieces, each 7', cut out of 14' 14
2 pieces, each 10', order 10' 20
4 pieces, each 11', order 12' 48
7 pieces, each 24', order 24' 168
3 pieces, each 20' 6", order 22' 66
4 pieces, each 12' 6", order 14' 56
2 pieces, each 13' 6", order 14 28
Total 1,004 1,673

Joists, 3" × 10"; 2½ ft. B. M., per lin. ft.:


(Headers) 2 pieces, each 8' 9", order 10' 20
2 pieces, each 6', cut out of 12' 12
5 pieces, each 9' 9", order 10' 50
11 pieces, each 19' 6", order 20' 220
302 755

Floor Framing,
Attic

Linear Feet
Quantities
Feet B. M.
Joists, 2" × 10"; 1⅔ ft. B. M., per lin. ft.:
15 pieces, each 14', order 14' 210
2 pieces, each 15' 6", order 16' 32
5 pieces, each 17', order 18' 90
3 pieces, each 15', order 16' 48
14 pieces, each 16', order 16' 224
2 pieces, each 7', cut out of 14' 14
2 pieces, each 10', order 10' 20
4 pieces, each 11', order 12' 48
7 pieces, each 24', order 24' 168
3 pieces, each 20' 6", order 22' 66
4 pieces, each 12' 6", order 14' 56
2 pieces, each 13' 6", order 14' 28
Total 1,004 1,673

Joists, 3" × 10"; 2½ ft. B. M., per lin. ft.:


2 pieces, each 8' 9", order 10' 20
2 pieces, each 6', cut out of 12' 12
5 pieces, each 9' 9", order 10' 50
11 pieces, each 19' 6", order 20' 220
Total 302 755

Floor Framing,
Front Porch

Linear Feet
Quantities
Feet B. M.
Joists, 3" × 9"; 2¼ ft. B. M., per lin. ft.:
3 pieces, each 7', cut out of 14' 21
1 piece, 6' 9", cut out of 14' 7
2 pieces, each 10', order 10' 20
1 piece, 8' 6", order 10' 10
Total 58 131
Joists, 2" × 6"; 1 ft. B. M., per lin. ft.:
2 pieces, each 21' 6", order 22' 44
2 pieces, each 19' 3", order 20' 40
4 pieces, each 8', cut out of 16' 32
1 piece, 10' 3", order 12' 12
6 pieces, each 9', order 10' 60
2 pieces, each 4' 6", cut out of 10' 10
5 pieces, each 6', cut out of 12' 30
3 pieces, each 2', cut out of 12' 6
4 pieces, each 5', cut out of 10' 20
3 pieces, each 9', order 10' 30
Total 284 284

Floor Framing,
Back Porches

Linear Feet
Quantities
Feet B. M.
Joists, 2" × 6"; 1 ft. B. M., per lin. ft.:
2 pieces, each 21', order 22' 44
3 pieces, each 8', order 8' 24
Total 68 68

Joists, 3" X 6"; 1½ ft. B. M., per lin. ft.:


[10]5 pieces, each 5' 9", cut out of 12' 36
12 pieces, each 6' 9", cut out of 14' 84
1 piece, 8' 6", order 10' 10
2 pieces, each 3' 6", cut out of 8' 8
Total 138 207

Bridging

Linear Feet
Quantities
Feet B. M.
2" × 4"; ⅔ ft. B. M., per lin. ft.:
First floor, 170 pieces, each 1' 6" 255
Second floor, 138 pieces, each 1' 6" 207
Third floor, 138 pieces, each 1' 6" 207
Total 669 446
Main-Roof Framing[11]

Linear Feet
Quantities
Feet B. M.
Rafters, 2" × 6"; 1 ft. B. M., per lin. ft.:
15 pieces, each 20', order 20' 300
14 pieces, each 19' 3", order 20' 280
1 piece, 18', order 18' 18
2 pieces, each 16', order 16' 32
2 pieces, each 14', order 14' 28
1 piece, 13' 4", order 14' 14
3 pieces, each 10' 6", order 12' 36
3 pieces, each 8' 6", order 10' 30
1 piece, 6' 9", order 8' 8
3 pieces, each 5', cut out of 16' 16
3 pieces, each 3', cut out of 10' 10
4 pieces, each 17', order 18' 72
1 piece, 12' 6", order 14' 14
1 piece, 10' 9", order 12' 12
2 pieces, each 9', order 10' 20
1 piece, 7', order 8' 8
18 pieces, each 9' 6", order 10' 180
2 pieces, each 13', order 14' 28
2 pieces, each 7' 9", cut out of 16' 16
2 pieces, each 6' 6", cut out of 14' 14
4 pieces, each 3' 6", cut out of 14' 14
4 pieces, each 8', cut out of 16' 32
2 pieces, each 11', order 12' 24
8 pieces, each 5' 3", cut out of 12' 48
1 piece, 6', cut out of 10' 6
2 pieces, each 2', cut out of 10' 4
8 pieces, each 11', order 12' 96
Total 1,360 1,360

Valley rafter, 3" × 10"; 2 ft. B. M., per lin. ft.:


1 piece, 24' 6", order 26' 65
Ridge plates, 2" × 10"; 1⅔ ft. B. M., per lin. ft.:
1 piece, 23' 6", order 24' 24
1 piece, 29' 3", 16' and 14', butted and cleated 30
1 piece, 9', order 10' 10
Total 64 107
Plates, 3" × 6"; 1½ ft. B. M., per lin. ft.:
4 pieces, each 10' 6", order 12' 72
Octagonal post, 6" × 6" × 3' 9

Porch-Roof Framing

Linear Feet
Quantities
Feet B. M.
Rafters, 2" × 6"; 1 ft. B. M., per lin. ft.:
2 pieces, each 9' 6", order 10' 20
22 pieces, each 8' 6", order 10' 220
4 pieces, each 6' 6", cut out of 14' 28
8 pieces, each 7', cut out of 14' 56
2 pieces, each 11', order 12' 24
Total 348 348

Rafters, 2" × 5"; ⅚ ft. B. M., per lin. ft.:


27 pieces, each 8', cut out of 16' 216
2 pieces, each 3' 6", cut out of 16' 8
8 pieces, each 6' 6", cut out of 14' 56
2 pieces, each 10' 6", cut out of 14' 21
2 pieces each, 3', cut out of 14' 6
Total 307 256

Plate, 5" × 10"; 4⅙ ft. B. M., per lin. ft.:


5 pieces, each 15', order 16' 80 333
Sills, 3" × 5"; 1¼ ft. B. M., per lin. ft.:
2 pieces, each 10', order 10' 20
5 pieces, each 9', order 10' 50
Total 70 88

Wall Studding
Linear Feet
Quantities
Feet B. M.
Wall plates, 4" × 11"; 3⅔ ft. B. M., per lin. ft.:
10 pieces, each 18', order 18' 180 660
Studs, 2" × 5"; ⁵/₆ ft. B. M., per lin. ft.:
[12]63 pieces, each 21', order 22' 1,386
106 pieces, each 12', order 12' 1,272
20 pieces, each 20', order 20' 400
10 pieces, each 8' 6", order 10' 100
Total 3,158 2,632

Partition Studding

Linear Feet
Quantities
Feet B. M.
First floor, 2" × 4"; ⅔ ft. B. M., per lin. ft.:
Studs, 160 pieces, each 9' 9", order 10' 1,600
Sills, 16 pieces, each 15', order 16' 256
Total 1,856 1,237
Second floor, 2" × 4"; ⅔ ft. B. M., per lin. ft.:
Studs, 180 pieces, each 9' 9", order 10' 1,800
Sills, 10 pieces, each 15', order 16' 160
Total 1,960 1,307
Attic, 2" × 4"; ⅔ ft. B. M., per lin. ft.:
Studs, 54 pieces, each 8' 9", order 10' 540
Studs, 133 pieces, each 6' 6", cut from 14' 938
Total 1,478 985

Miscellaneous

Linear Feet
Quantities
Feet B. M.
Lookouts:
50 pieces, each 3" × 1" × 2', cut from 8' 25
37 pieces, each 6" × 1" × 2', cut from 8' 37
Furring, for brick walls, 1" × 2"; ⅙ ft. B. M., per lin. ft.:
125 pieces, each 11', order 12' 1,500 250
Grand total of framing 18,578

Cost
The price of the framing is based on the following cost of 1,000
feet board measure of hemlock, which includes framing.
1,000 ft. of hemlock $28.00
Nails and spikes, allowing 100 lb. to 3,000 ft.
of lumber, at $2 per 100 pounds .67
[13]Cost of framing, per 1,000 feet of lumber 12.00
Cost per thousand feet B. M. $40.67

Summary
The amount of material, as previously estimated, is 18,578 ft.
B. M., which, at $40.67 per M, will make the total cost of
framing $755.57.

Sheathing

Feet
Quantities
B. M.
Main roof, 2,200 sq. ft. × 1 in 2,200
Tower roof, 370 sq. ft. × 1 in 370
Porch roof, 637 sq. ft. × 1 in 637
Outside walls, laid diagonally,
2,417 sq. ft. + 10 per cent. 2,659
Total sheathing 5,866

Shingles

Quantities
Area to be covered (see wall sheathing),
2,417 sq. ft.= 24.2 squares
Shingles, 4 in. wide, and 5 in. exposure,
number per square 720
Number of shingles required, 24.2 × 720 17,424
Add 5 per cent. for waste 871
Total shingles 18,295
Cost
The cost of sheathing in place is assumed to be the same
as that for hemlock lumber, $40.67 per M. The total sheathing
is 5,866 square feet, which, at $40.67 per M, will make the
cost of sheathing $238.57.
The cost of shingles is based on the following analysis of
the cost of 1,000 shingles in place:
1,000 shingles XXXX $ 5.50
[14]Labor: one man can lay about 700 shingles per day;
wages being $3.20, 1,000 will cost 4.57
Nails (about) .25
Cost per thousand $10.32

From the preceding estimate, the number of shingles required is 18,295,


which, at $10.32 per 1,000, will make the cost of shingles in place $188.80.
Summary
Sheathing $238.57
Shingles 188.80
Total cost of sheathing and shingles $427.37

Flooring

Square
Quantities
Feet
First floor, area (net) 1,312
Second floor, area (net) 1,312
Attic floor, area (net) 1,071
Porch floors, area (net) 523

Hemlock Underflooring
Unmatched underflooring is used under the first and second
floor. Its quantity is 1,312 × 2 = 2,624 feet B. M.
Rift-Sawed Yellow-Pine
Finish Flooring
The total area of the first, second, and third floors is 3,695
square feet. Adding 25 per cent. for waste, the quantity of ⅞-
inch flooring is 3,695 square feet + (3,695 × .25) = 4,619 feet
B. M.
Yellow-Pine
Porch Flooring
Increasing the net area of the porch floor by 25 per cent.,
the flooring required is 523 square feet + (523 × .25) = 654
feet B. M.
Cost
The estimated cost of flooring may be analyzed as follows:
Cost of 1,000 Feet B. M., Rough Flooring
[15]1,000 ft. B. M., hemlock $27.00
Labor 10.00
Nails, 33 lb., at $2 per 100 pounds .67
Cost per thousand feet B. M. $37.67

Cost of 1,000 Feet B. M., Finish Flooring


1,000 ft. B. M., rift-sawed yellow pine $55.00
Labor, including striking joints 16.00
Nails .67
Cost per thousand feet B. M. $71.67

Cost of 1,000 Feet B. M., Porch Flooring


1,000 ft. B. M., No. 1 yellow pine $45.00
Labor 16.00
White lead for joints (about) .50
Nails .67
Cost per thousand feet B. M. $62.17

Summary
Hemlock, 2,624 ft. B. M., at $37.67 per M $98.85
Rift-sawed yellow pine, 4,619 ft. B. M., at $71.67 per M 331.04
Yellow pine, 654 ft. B. M., at $62.17 per M 40.66
Total cost of flooring $470.55

Porch Ceiling,
Yellow Pine
Feet
Quantities
B. M.
Porch ceiling, same as porch flooring 654
Cost
The cost of yellow-pine ceiling is $45 per thousand feet B. M. Since there is
no white lead to be used and the joints are not struck, $11 will pay for laying
it. The nails will cost 67 cents, which will bring the cost per thousand feet B.
M., up to $56.67. Therefore, 654 feet B. M., yellow-pine ceiling, at $56.67 per
thousand, will cost $37.06.
Cornice, Spandrels, Etc.,
White-Pine Dressed Lumber
Cost
Cornice, 393 lin. ft., at 50 cents per foot $196.50
Spandrels, 357 lin. ft., at 12 cents per foot 42.84
Base, 128 lin. ft., at 6 cents per foot 7.68
16 porch posts, 8" × 8" × 9' at $4 each 64.00
Total $311.02

Summary
Yellow-pine ceiling $ 37.06
White-pine dressed lumber 311.02
Total $348.08

Recapitulation of Cost of Carpentry


Framing $755.57
Sheathing and shingles 427.37
Flooring 470.55
Porch ceiling, cornice, etc. 348.08
Total cost of carpentry $2,001.57

ROOFING
6. Roof framing and sheathing are included in the estimate for carpentry.
Following are given the estimates for slating and miscellaneous roof items:

Slating

Quantities Squares
Main and dormer roofs 22.0
Porch roof 6.4
Tower roof 3.7
32.1
Cost
The price of slating per square is given in Table XII, Estimating and
Calculating Quantities, Part 1. Bangor slating costs $8 per square. On account
of the curved tower and the number of hips and valleys, and because the
measurement just given is actual measurement, the price will be put at $10
per square. Thus, the cost of 32.1 squares at $10 will be $321.

Miscellaneous Items[16]

Quantities and Cost


Tin roof on bay window, 38 sq. ft. at 20 cents per square foot $ 7.60
Tin for valleys, 191 sq. ft., at 18 cents per square foot 34.38
Flashing around chimneys and dormers, 90 sq. ft.,
at 10 cents per square foot 9.00
Gutters, 100 lin. ft., 26 in. wide, at 28 cents per foot 28.00
Conductor pipe, 4-inch galvanized iron, 146 lin. ft.,
at 20 cents per linear foot 29.20
Terra-cotta ridge tiles, 70 lin. ft., at $1 per linear foot 70.00
3 terra-cotta finials, 2 ft. high, at $8 each 24.00
Tower finial, copper 30.00
Total $232.18

Recapitulation of Cost of Roofing


Slating $321.00
Miscellaneous 232.18
Total cost of roofing $553.18

LATHING AND PLASTERING


7. Plastering varies in price according to its position and quality. It is
therefore necessary to make a separate schedule of each class of work, so that
any increase or decrease in quantity may be easily added to or deducted from
the estimate.

Three-Coat Work

Square Square
Quantities Feet Yards
First-story walls, 542' × 9' 9⅜" 5,284.5
First-story ceiling (take measurement of flooring) 1,312.0
Second-story walls, 609' × 9' 5,481.0
Second-story ceiling 1,312.0
Attic walls, 190' × 8' + 156' × 6' 2,456.0
Attic ceiling 831.0
Total of three-coat plastering 16,676.5 1,853

Two-Coat Work

Square Square
Quantities Feet Yards
Cellar ceiling, use same measurements
as for concrete cellar floor 139.9

Cornices

Linear
Quantities
Feet
Cornice, 147' of 2' girth 147
Cornice, 493' of 1' girth 493

Cost
The cost of three-coat plastering is given in Estimating and
Calculating Quantities, Part 1, as 31 cents per square yard, and
two-coat work, as 23 cents per square yard. According to the
same section, lathing costs 12 cents per square yard.
Therefore, lathing and plastering for three-coat work cost 43
cents per square yard, and for two-coat work, 35 cents per
square yard.
The assumed cost of plain, run stucco cornice per linear
foot of 2-foot girth is 31½ cents, and the cost per linear foot of
that having a 1-foot girth is 27 cents.
Summary
From the preceding estimates of quantities and costs, the
following figures are obtained:
1,853 sq. yd. of three-coat work,
at 43 cents per square yard $ 796.79
139.9 sq. yd. of two-coat work,
at 35 cents per square yard 48.97
147 ft. of cornice at 31½ cents 46.31
493 ft. of cornice at 27 cents 133.11
Total cost of plastering $1,025.18

JOINERY
8. As there are so many different sizes in the joinery work, no attempt has
been made to make detailed estimates of the cost of each; but the general
method of obtaining the costs is that given in the articles on Joinery, in
Estimating and Calculating Quantities, Part 1. Since the quality of the work
varies in different parts of the building it will be found that one unit price will
not be sufficient, but experience is needed to fix the unit price for different
classes of work.

Door Frames, First Floor

Quantities and Cost


Chestnut frames—jambs 1⅛" rabbeted; casing ⅞" × 5½",
with ¼-inch edge mold; back-band molding ⅞" × 2";
plinth and corner blocks:
1 frame, 3' 2" × 7' 9" × 6" (vestibule) $ 4.16
1 frame, 3' 2" × 7' 9" × 9" (3-inch jamb), front door 4.68
1 frame, 5' 6" × 7' 9" × 14" (sliding-door) 13.60
1 frame, 4' × 7' 9" × 14" (sliding-door) 9.35
1 frame, 3' × 7' 9" × 14" (sliding-door) 6.80
2 frames, 2' 8" × 7' 9" × 6", $4.16 each 8.32
2 frames, 22" × 7' 9" × 4", $2.21 each 4.42

White pine—jambs 6" × 1⅛" rabbeted; casings ⅞" × 5";


back-band molding 2" × ⅞"; plinth and corner blocks:
4 frames, 2' 8" × 7' 9", $3.70 each 14.80
2 frames, 2' 6" × 7' 9", $3.61 each 7.22
1 frame, 2' 10" × 7' 9" 3.78
Total $77.13

Door Frames, Second Floor

Quantities and Cost


White pine, similar to first floor:
8 frames, 2' 8" × 7' 6", $3.57 each $28.56
6 frames, 2' 6" × 7' 6", $3.50 each 21.00
1 frame, 2' 2" × 7' 6" 3.19
1 frame, 2' 4" × 7' 6" 3.40
1 frame, 2' 6" × 7' 3.19
Total $59.34

Door Frames, Attic

Quantities and Cost


White pine, similar to second-floor doors:
6 frames, 2' 8" × 6' 8" at $3.19 $19.14
1 frame, 2' 6" × 6' 6" 3.06
Total $22.20

Summary
First floor $ 77.13
Second floor 59.34
Attic 22.20
Total cost of door frames $158.67

Doors, First Story[17]

Quantities and Cost


Veneered chestnut, six and seven raised panels,
planted moldings:
1 pair sliding, 2' 9" × 7' 9" × 2" $ 15.90
1 single sliding, 4' × 7' 9" × 2" 11.34
1 single sliding, 3' × 7' 9" × 2" 8.97
1 lavatory, 2' 4" × 6' × 1¾"
(frame included in paneling) 4.93
2 closet doors, 22" × 7' 9" × 1¾", solid molded,
including glass in upper panel, at $5 each 10.00
1 front door, 3' 2" × 7' 9" × 2¼", three-panel,
glass in top panel, price, including glass 12.75
1 vestibule door, 3' 2" × 7' 9" × 2¼", three-panel,
glass in top panel, price, including glass 12.75
Veneered chestnut and pine doors:
1 in butler's pantry, 2' 8" × 7' 9" × 2" 7.50
1 in butler's pantry, 2' 8" × 7' 9" × 1¾" 6.71
White-pine doors, raised panels:
2 glass doors, 2' 4" × 5' × 1¼", one-panel, at $3
(china closet, no frames) 6.00
4 doors, 2' 8" × 7' 9" × 1¾", five-panel,
solid moldings, at $4.13 each 16.52
2 doors, 2' 6" × 7' 9" × 1¾", five-panel,
solid moldings, at $3.91 each 7.82
1 door, 2' 10" × 7' 9" × 2", five-panel, solid molded 6.59
2 outside cellar doors, at $2 each 4.00
Total $131.78

Doors, Second Floor

Quantities and Cost


1½-inch white pine, five-panel, solid molded, raised panels:
8 doors, 2' 8" × 7' 6", at $4 $32.00
6 doors, 2' 6" × 7' 6", at $3.75 22.50
1 door, 2' 6" × 3' 6" 1.75
1 door, 2' 2" × 7' 6" 3.20
1 door, 2' 4" × 7' 6" 3.40
2 wardrobe doors, 2' 2" × 6' × 1¼",
including glass panels, at $2 each 4.00
Total $66.85

Doors, Attic

Quantities and Cost


White pine, similar to second floor:
[18]1 stuck-molded door, 2' 6" × 6' 6", glass panel $ 4.70
6 doors, 2' 8" × 6' 8", at $3.60 21.60
Total $ 26.30

Summary
First story $131.78
Second story 66.85
Attic 26.30
Total cost of doors $224.93

Window Frames, Cellar


Quantities and Cost
No. 2 white pine, 1½" × 7" rabbeted jambs and head,
and 2" × 7" sill. Complete, set in place:
1 window, 3 lights, 13" × 10" $ 1.16
2 windows, 1 light, 16" × 10", at 48 cents each .96
4 windows, 2 lights, 14" × 10", at 83 cents each 3.32
3 windows, 2 lights, 11" × 10", at 66 cents each 1.98
2 windows, 2 lights, 13" × 10", at 78 cents each 1.56
1 window, 3 lights, 11" × 10" .99
Total $ 9.97

Window Frames,
First Story

Quantities and Cost


Box frames, pulley stiles and hanging stiles 1⅛", sills 2",
and outer casing ⅞", all of No. 2 white pine.
Inside casing chestnut, with molded back band
5½" × ⅞", stool 4" × 1⅛", apron 5" × ⅞",
sash stop ½" × 1½".
Frames in brickwork. Complete, set in place:
1 window, 2 lights, 40" × 32" $ 7.80
2 windows, 2 lights, 18" × 32", at $3.16 each 6.32
1 window, 2 lights, 24" × 32" 4.18
1 window, 2 lights, 34" × 32" 5.88
2 windows, 2 lights, 36" × 32", curved, at $12.24 24.48
1 window, 2 lights, 30" × 32" 5.10
1 window, 2 lights, 22" × 24" 2.80
1 window, 4 lights, 31" × 32" (double) 10.55
2 windows, 6 lights, 15" × 28" (casement), at $6.70 13.40
Total $80.51
Pulley stiles 1⅛", sill 2", sub-sills 1⅛", outside casings ⅞",
inside casing with molded back band 5½" × ⅞",
stool 4" × 1⅛", apron 5" × ⅞", sash stop ½" × 1½",
all of white pine.
Frames in wooden walls. Complete, set in place:
1 window, single light, 14" × 28" $ 1.04
3 windows, 2 lights, 26" × 32", at $4.42 each 13.26
1 window, 2 lights, 22" × 32" 3.74
Total $18.04
Window Frames,
Second Story

Quantities and Cost


1 window, single light, 14" × 28" $ 1.04
2 windows, 2 lights, 44" × 28", at $6.54 each 13.08
2 windows, 2 lights, 23" × 28", at $3.40 each 6.80
3 windows, 2 lights, 28" × 28", at $4.18 each 12.54
2 windows, 2 lights, 36" × 28" (curved), at $10.72 each 21.44
3 windows, 2 lights, 26" × 28", at $3.90 each 11.70
1 window, 2 lights, 20" × 28" 2.98
4 windows, 2 lights, 30" × 38", at $6.07 each 24.28
Total $93.86

Window Frames,
Attic

Quantities and Cost


2 windows, 2 lights, 18" × 18", at $1.69 each $ 3.38
1 window (circular), 24" diameter 2.27
2 double windows, 4 lights, 22" × 24" (curved),
at $11.22 each 22.44
1 double window, 4 lights, 21" × 24" 5.35
1 double window, 4 lights, 28" × 20" 5.96
1 double window, 4 lights, 24" × 20" 5.10
1 window, 2 lights, 28" × 20" 2.98
1 window, 2 lights, 30" × 28" 4.46
Total $51.94

Summary
Cellar $ 9.97
First story in brick walls 80.51
First story in frame 18.04
Second story 93.86
Attic 51.94
Total cost of window frames $254.32

Window Sash,
Cellar
Quantities and Cost
1½-inch white pine, glazed (double American),
price not including hardware:
1 sash, 3 lights, 13" × 10" $ 1.14
2 sashes, single light, 16" × 10", at 47 cents each .94
4 sashes, 2 lights, 14" × 10", at 82 cents each 3.28
3 sashes, 2 lights, 11" × 10", at 64 cents each 1.92
2 sashes, 2 lights, 13" × 10", at 76 cents each 1.52
1 sash, 3 lights, 11" × 10" .96
Total $ 9.76

Window Sash,
First Story

Quantities and Cost


Chestnut, 1¾ inch, prices including glazing (double American),
hanging sash, and putting on stops:
1 pair, single light, 40" × 32" $ 7.47
2 pair, single light, 18" × 32", at $3.36 per pair 6.72
1 pair, single light, 24" × 32" 4.48
1 pair, single light, 34" × 32" 6.35
2 pair, single light, 36" × 32" (curved), at $20.16 per pair 40.32
2 pair, single light, 31" × 32", at $5.79 per pair 11.58
1 pair, single light, 30" × 32" 5.60
1 pair, single light, 22" × 24" 3.08
2 pair, 3 lights, 15" × 28" (casement), at $7.35 per pair 4.70
Pine:
1 sash, single light, 14" × 28" 1.14
3 pair, single light, 26" × 32", at $4.85 per pair 14.55
1 pair, single light, 22" × 32" 4.11
Total $120.10

Window Sash,
Second Story

Quantities and Cost


Pine:
1 sash, single light, 14" × 28" $ 1.14
2 pair, single light, 44" × 28", at $7.19 per pair 14.38
2 pair, single light, 23" × 28", at $3.76 per pair 7.52
3 pair, single light, 28" × 28", at $4.57 per pair 13.71
2 pair, single light, 36" × 28" (curved), at $17.64 per pair 35.28
3 pair, single light, 26" × 28", at $4.25 per pair 12.75
1 pair, single light, 20" × 28" 3.27
4 pair, single light, 30" × 28", at $4.90 per pair 19.60
Total $107.70

Window Sash,
Attic

Quantities and Cost


2 pair, single light, 18" × 18", at $1.89 per pair $ 3.78
1 sash, circular, 24-inch diameter 2.52
4 pair, single light, 22" × 24" (curved), at $9.24 per pair 36.96
2 pair, single light, 21" × 24", at $2.94 per pair 5.88
3 pair, single light, 28" × 20", at $3.27 per pair 9.81
2 pair, single light, 24" × 20", at $2.80 per pair 5.60
1 pair, single light, 30" × 28" 4.90
Total $ 69.45

Screen Frames
for Porch

Quantities and Cost


Rails and stiles, white pine, 4" × 1½", two muntins each:
1 frame, 36" × 16" $ .51
1 frame, 90" × 16" 1.27
1 frame, 88" × 16" 1.25
1 frame, 60" × 16" .85
2 frames, 94" × 16", at $1.33 each 2.66
2 frames, 66" × 16", at 93 cents each 1.86
1 frame, 24" × 16" .34
1 frame, 84" × 16" 1.19
1 frame, 20" × 16" .33
Total $ 10.26

Summary
Cellar $ 9.76
First story 120.10
Second story 107.70
Attic 69.45
Screens 10.26
Total cost of window sash $ 317.27

Cellar Stairs

Quantities and Cost


52 ft. of hemlock, at 3 cents per foot $ 1.56
46 ft. of planed white pine, at 4½ cents per foot 2.07
Labor: 12 risers, at 20 cents each 2.40
Total $ 6.03

Back Stairs

Quantities and Cost


72 ft. ⁵/₄ planed white pine, at 6 cents per foot $ 4.32
White-pine hand rails, 18 ft., at 6 cents per foot 1.08
Labor: 13 risers, at 40 cents each 5.20
Total 5.20

Main Stairs

Quantities and Cost


335 ft. of hemlock, at 3 cents per foot $ 10.05
185 ft. of chestnut, at 10 cents per foot 18.50
49 ft. of chestnut hand rail, at 60 cents per foot 29.40
86 turned chestnut balusters, 2" × 2" × 10", at 12 cents each 10.32
1 box newel, 8" × 8" × 4' 6", chestnut, paneled, with molded cap 6.00
7 newels, 5" × 5" × 4' 6", chestnut, with turned pendants, at $4 28.00
2 newels, 5" × 5" × 12', chestnut, with turned caps, at $6 12.00
Spandrel, 30 sq. ft., 10 raised panels, ⅞-inch thick
stiles and rails, 1¼-inch thick planted molding,
at 35 cents per square foot 10.50
Paneled partition under stairs, chestnut, 17 sq. ft.,
at 35 cents per square foot 5.95
String molding, 46' of 1½" × 3", chestnut, at 3½ cents 1.61
Skirt molding, 46' of 1½" × ¾", chestnut, 1¼ cents .58
Soffit molding, 38' of ⅝" × 2", chestnut, 1½ cents .57
Labor: 35 risers, at $2 each 70.00
Total $203.48
Summary
Cellar stairs $ 6.03
Back stairs 10.60
Main stairs 203.48
Total cost of stairs $220.11

Miscellaneous
Interior Joinery

Baseboard
First story:
Chestnut, ⅞" × 6", with molding worked on face,
tongued into surbase, 1⅛" × 6", 139 ft.,
at 30 cents per linear foot $ 41.70
White pine, ⅞" × 9", plain, 90 ft.,
at 33 cents per linear foot 29.70
Second story:
White pine, ⅞" × 9", molded, 300 ft.,
at 33 cents per linear foot 99.00
Attic:
White pine, ⅞" × 6", molded, 290 ft., at 24 cents 69.60
Total $240.00

Wainscoting
First story:
Chestnut, ⅞" × 2½", beaded and matched boards,
4 ft. high, 33 ft. long, 132 sq. ft.,
at 8 cents per square foot, dining room $ 10.56
Molded cap, 1½" × 1½", 33 ft., at 3 cents per foot .99
Chestnut, paneled, 67' × 4' high = 268 sq. ft.,
at 35 cents per square foot 93.80
Molded cap, 1¼" × 4", 67 ft., at 10 cents per foot 6.70
Second story (bathroom):
White pine, ⅞" × 2½", matched boards, 4 ft. high,
128 sq. ft., at 8 cents per square foot 10.24
Molded cap, 1½" × 1½", 32 ft., at 3 cents per foot .96
Total $123.25

Picture Molding
Chestnut, 3" × 1½", 231 ft., at 9 cents $ 20.79

China Closet
Chestnut, dressed, 97 ft. B. M., at 10 cents per foot $ 9.70
Crown molding, 1" × 3", 8 ft., at 8 cents per foot .64
Labor: 1 man, 2 days, at $3.20 6.40
Total $ 16.74

Shelving
No. 2 white pine, 50 ft. B. M., at 4½ cents per foot $ 2.25
Labor: 1 man, 1 day, at $3.20 3.20
Total $ 5.45

Summary
Baseboard $240.00
Wainscoting 123.25
Picture molding 20.79
China closet 16.74
Shelving 5.45
Total cost of miscellaneous interior joinery $406.23

Miscellaneous Exterior Work

Moldings
356 ft. crown molding, 1" × 4", at 5½ cents $ 19.58
356 ft. bed molding, 1" × 3", at 4 cents 14.24
356 ft. bed molding, 1" × 1½", at 3 cents 10.68
74 ft. bed molding, 1" × 2", at 3 cents 2.22
356 ft. bed molding, ½" × ⅞", at 1½ cents 5.34
64 ft. neck molding, at 1 cent .64
36 ft. cove molding, ⅞" × 1⅛", at 3 cents 1.08
White pine:
35 ft. triglyphs, at 10 cents 3.50
207 turned balusters, 2" × 1' 6", for porches, at 10 cents 20.70
92 ft. molded hand rail, 5" × 3", at 11 cents 10.12
92 ft. bottom rail, 5" × 3", at 11 cents 10.12
200 dentils, 2" × 2" × 3", at 1½ cents 3.00
137 ft. window cap, 3" × 1½", at 3 cents 4.11
23 ft. B. M., for balustrade posts, at 4½ cents 1.04
Casing for circular window 1.00
Semicircular head-casing over outside door in dormer 2.00
Total cost of exterior work $109.37

Recapitulation of Cost of Joinery


Door frames $158.67
Doors 224.93
Window frames 254.32
Window sash 317.27
Stairs 220.11
Miscellaneous interior joinery 406.23
Miscellaneous exterior work 109.37
Total cost of joinery $1,690.90

HARDWARE
9. The prices given in the following list are based on the use of the best
quality of hardware in the market. Should inferior quality be used, these prices
would probably be 50 per cent. less. The cost of labor is assumed to be one-
fifth the cost of the hardware.

Locks

Quantities and Cost


One 5⅜-inch mortise front-door lock,
with bronze furniture complete $6.00
One 4½-inch mortise vestibule-door lock,
with bronze furniture complete 5.50
One 5½-inch flush pull mortise lock for double sliding-door 3.00
Two 5½-inch flush pull mortise locks for single sliding-door,
at $2.25 4.50
Eighteen 4½-inch mortise knob locks, at $2.20 39.60
Ten 4-inch cupboard lock sets, at $1.85 18.50
Six 2⅜-inch mortise knob locks, at $1.50 9.00
One 2-inch steel spring padlock .50
Total $86.60

Hinges

Quantities and Cost


1 pair double-acting checking spring hinges
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like