100% found this document useful (2 votes)
226 views

Immediate download Learn to Code by Solving Problems A Python Programming Primer 1st Edition Daniel Zingaro ebooks 2024

The document promotes the ebook 'Learn to Code by Solving Problems: A Python Programming Primer' by Daniel Zingaro, available for download on ebookmeta.com. It includes links to various editions of the book and other recommended digital products. The book aims to teach Python programming through problem-solving and is published by No Starch Press.

Uploaded by

makanmelvea2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
226 views

Immediate download Learn to Code by Solving Problems A Python Programming Primer 1st Edition Daniel Zingaro ebooks 2024

The document promotes the ebook 'Learn to Code by Solving Problems: A Python Programming Primer' by Daniel Zingaro, available for download on ebookmeta.com. It includes links to various editions of the book and other recommended digital products. The book aims to teach Python programming through problem-solving and is published by No Starch Press.

Uploaded by

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

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Learn to Code by Solving Problems A Python


Programming Primer 1st Edition Daniel Zingaro

https://ebookmeta.com/product/learn-to-code-by-solving-
problems-a-python-programming-primer-1st-edition-daniel-
zingaro-2/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


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

Learn to Code by Solving Problems A Python Programming


Primer 1st Edition Daniel Zingaro

https://ebookmeta.com/product/learn-to-code-by-solving-problems-a-
python-programming-primer-1st-edition-daniel-zingaro/

ebookmeta.com

Learn to Code by Solving Problems A Python Programming


Primer 1st Edition Daniel Zingaro

https://ebookmeta.com/product/learn-to-code-by-solving-problems-a-
python-programming-primer-1st-edition-daniel-zingaro-3/

ebookmeta.com

Learn to Code by Solving Problems Daniel Zingaro

https://ebookmeta.com/product/learn-to-code-by-solving-problems-
daniel-zingaro/

ebookmeta.com

Rasch Measurement Theory Analysis in R 1st Edition Cheng


Hua

https://ebookmeta.com/product/rasch-measurement-theory-analysis-
in-r-1st-edition-cheng-hua/

ebookmeta.com
Beneath Cold Earth 1st Edition M S Morris

https://ebookmeta.com/product/beneath-cold-earth-1st-edition-m-s-
morris/

ebookmeta.com

Fearless Like Us 1st Edition Krista Ritchie

https://ebookmeta.com/product/fearless-like-us-1st-edition-krista-
ritchie/

ebookmeta.com

Dating the Virgin 1st Edition Piper Cook

https://ebookmeta.com/product/dating-the-virgin-1st-edition-piper-
cook/

ebookmeta.com

Empowerment for Teaching Excellence Through Virtuous


Agency 1st Edition Lötter Hennie

https://ebookmeta.com/product/empowerment-for-teaching-excellence-
through-virtuous-agency-1st-edition-lotter-hennie/

ebookmeta.com

Connected and Disconnected in Viet Nam Remaking Social


Relations in a Post Socialist Nation 1st Edition Philip
Taylor
https://ebookmeta.com/product/connected-and-disconnected-in-viet-nam-
remaking-social-relations-in-a-post-socialist-nation-1st-edition-
philip-taylor/
ebookmeta.com
Shaw 1st Edition Milly Taiden

https://ebookmeta.com/product/shaw-1st-edition-milly-taiden/

ebookmeta.com
LEARN TO CODE BY
SOLVING PROBLEMS
A Python Programming Primer

by Daniel Zingaro

San Francisco
LEARN TO CODE BY SOLVING PROBLEMS. Copyright © 2021 by Daniel
Zingaro.

All rights reserved. No part of this work may be reproduced or transmitted in any
form or by any means, electronic or mechanical, including photocopying,
recording, or by any information storage or retrieval system, without the prior
written permission of the copyright owner and the publisher.

ISBN-13: 978-1-7185-0132-4 (print)


ISBN-13: 978-1-7185-0133-1 (ebook)

Publisher: Bill Pollock


Executive Editor: Barbara Yien
Production Manager: Rachel Monaghan
Production Editor: Kassie Andreadis
Developmental Editor: Alex Freed
Interior and Cover Design: Octopod Studios
Cover Illustrator: Rob Gale
Technical Reviewer: Luke Sawczak
Copyeditor: Kim Wimpsett
Proofreader: Emelie Battaglia
Indexer: Sanjiv Kumar Sinha

For information on book distributors or translations, please contact No Starch


Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; info@nostarch.com
www.nostarch.com

Library of Congress Cataloging-in-Publication Data


Names: Zingaro, Daniel, author.
Title: Learn to code by solving problems : a Python programming primer / by
Daniel Zingaro.
Description: San Francisco, CA : No Starch Press, [2021] | Includes index.
Identifiers: LCCN 2021011082 (print) | LCCN 2021011083 (ebook) | ISBN
9781718501324 (print) | ISBN 9781718501331 (ebook)
Subjects: LCSH: Python (Computer program language) | Computer programming.
Classification: LCC QA76.73.P98 Z55 2021 (print) | LCC QA76.73.P98
(ebook) | DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2021011082
LC ebook record available at https://lccn.loc.gov/2021011083

No Starch Press and the No Starch Press logo are registered trademarks of No
Starch Press, Inc. Other product and company names mentioned herein may be
the trademarks of their respective owners. Rather than use a trademark symbol
with every occurrence of a trademarked name, we are using the names only in an
editorial fashion and to the benefit of the trademark owner, with no intention of
infringement of the trademark.

The information in this book is distributed on an “As Is” basis, without warranty.
While every precaution has been taken in the preparation of this work, neither
the author nor No Starch Press, Inc. shall have any liability to any person or
entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in it.
To Dad, for the computer code

and
To Mom, for the teacher code
About the Author
Dr. Daniel Zingaro is an associate teaching professor of computer
science and award-winning teacher at the University of Toronto. His
main area of research is computer science education, where he studies
how students learn (and sometimes don’t learn) computer science
material. He is the author of Algorithmic Thinking (No Starch Press,
2021), a book that helps learners understand and use algorithms and data
structures.
About the Technical Reviewer
Luke Sawczak is a frequent freelance editor and hobby programmer; his
favorite projects include a prose-to-poetry converter, a visual aid for
cutting the right number of slices of cake, and a version of Boggle that
uses numbers made for math tutors. He currently teaches French and
English on the outskirts of Toronto. He also writes poetry and composes
for the piano, which he would do for a living if he could. He can be
found online at https://sawczak.com/.
BRIEF CONTENTS
Acknowledgments
Introduction
Chapter 1: Getting Started
Chapter 2: Making Decisions
Chapter 3: Repeating Code: Definite Loops
Chapter 4: Repeating Code: Indefinite Loops
Chapter 5: Organizing Values Using Lists
Chapter 6: Designing Programs with Functions
Chapter 7: Reading and Writing Files
Chapter 8: Organizing Values Using Sets and Dictionaries
Chapter 9: Designing Algorithms with Complete Search
Chapter 10: Big O and Program Efficiency
Afterword
Appendix: Problem Credits
Index
CONTENTS IN DETAIL
ACKNOWLEDGMENTS

INTRODUCTION
Online Resources
Who This Book Is For
Why Learn Python?
Installing Python
Windows
macOS
Linux
How to Read This Book
Using Programming Judges
Making Your Programming Judge Accounts
The DMOJ Judge
The Timus Judge
The USACO Judge
About This Book

1
GETTING STARTED
What We’ll Be Doing
The Python Shell
Windows
macOS
Linux
Problem #1: Word Count
The Challenge
Input
Output
Strings
Representing Strings
String Operators
String Methods
Integer and Floating-Point Numbers
Variables
Assignment Statement
Changing Variable Values
Counting the Words Using a Variable
Reading Input
Writing Output
Solving the Problem: A Complete Python Program
Launching a Text Editor
The Program
Running the Program
Submitting to the Judge
Problem #2: Cone Volume
The Challenge
Input
Output
More Math in Python
Accessing Pi
Exponents
Converting Between Strings and Integers
Solving the Problem
Summary
Chapter Exercises
Notes

2
MAKING DECISIONS
Problem #3: Winning Team
The Challenge
Input
Output
Conditional Execution
The Boolean Type
Relational Operators
The if Statement
if by Itself
if with elif
if with else
Solving the Problem
Problem #4: Telemarketers
The Challenge
Input
Output
Boolean Operators
or Operator
and Operator
not Operator
Solving the Problem
Comments
Input and Output Redirection
Summary
Chapter Exercises
Notes

3
REPEATING CODE: DEFINITE LOOPS
Problem #5: Three Cups
The Challenge
Input
Output
Why Loops?
for Loops
Nesting
Solving the Problem
Problem #6: Occupied Spaces
The Challenge
Input
Output
A New Kind of Loop
Indexing
Range for loops
Range for Loops Through Indices
Solving the Problem
Problem #7: Data Plan
The Challenge
Input
Output
Looping to Read Input
Solving the Problem
Summary
Chapter Exercises
Notes

4
REPEATING CODE: INDEFINITE LOOPS
Problem #8: Slot Machines
The Challenge
Input
Output
Exploring a Test Case
A Limitation of for loops
while loops
Using while loops
Nesting Loops in Loops
Adding Boolean Operators
Solving the Problem
The Mod Operator
F-Strings
Problem #9: Song Playlist
The Challenge
Input
Output
String Slicing
Solving the Problem
Problem #10: Secret Sentence
The Challenge
Input
Output
Another Limitation of for loops
while Loops Through Indices
Solving the Problem
break and continue
break
continue
Summary
Chapter Exercises
Notes

5
ORGANIZING VALUES USING LISTS
Problem #11: Village Neighborhood
The Challenge
Input
Output
Why Lists?
Lists
List Mutability
Learning About Methods
List Methods
Adding to a List
Sorting a List
Removing Values from a List
Solving the Problem
Avoiding Code Duplication: Two More Solutions
Using a Huge Size
Building a List of Sizes
Problem #12: School Trip
The Challenge
Input
Output
A Catch
Splitting Strings and Joining Lists
Splitting a String into a List
Joining a List into a String
Changing List Values
Solving Most of the Problem
Exploring a Test Case
The Code
How to Handle the Catch
Exploring a Test Case
More List Operations
Finding the Index of the Maximum
Solving the Problem
Problem #13: Baker Bonus
The Challenge
Input
Output
Representing a Table
Exploring a Test Case
Nested Lists
Solving the Problem
Summary
Chapter Exercises
Notes

6
DESIGNING PROGRAMS WITH FUNCTIONS
Problem #14: Card Game
The Challenge
Input
Output
Exploring a Test Case
Defining and Calling Functions
Functions Without Arguments
Functions with Arguments
Keyword Arguments
Local Variables
Mutable Parameters
Return Values
Function Documentation
Solving the Problem
Problem #15: Action Figures
The Challenge
Input
Output
Representing the Boxes
Top-Down Design
Doing Top-Down Design
The Top Level
Task 1: Read Input
Task 2: Check Whether All Boxes Are OK
Task 3: Obtain a New List of Boxes with Only Left and Right
Heights
Task 4: Sort Boxes
Task 5: Determine Whether Boxes Are Organized
Putting It All Together
Summary
Chapter Exercises
Notes

7
READING AND WRITING FILES
Problem #16: Essay Formatting
The Challenge
Input
Output
Working with Files
Opening a File
Reading from a File
Writing to a File
Solving the Problem
Exploring a Test Case
The Code
Problem #17: Farm Seeding
The Challenge
Input
Output
Exploring a Test Case
Top-Down Design
The Top Level
Task 1: Read Input
Task 2: Identify Cows
Another Random Document on
Scribd Without Any Related Topics
ON PERSONAL IDENTITY

The Monthly Magazine.]


[January, 1828.
‘Ha! here be three of us sophisticated.’—Lear.

‘If I were not Alexander, I would be Diogenes!’ said the


Macedonian hero; and the cynic might have retorted the compliment
upon the prince by saying, that, ‘were he not Diogenes, he would be
Alexander!’ This is the universal exception, the invariable reservation
that our self-love makes, the utmost point at which our admiration
or envy ever arrives—to wish, if we were not ourselves, to be some
other individual. No one ever wishes to be another, instead of
himself. We may feel a desire to change places with others—to have
one man’s fortune—another’s health or strength—his wit or learning,
or accomplishments of various kinds—
‘Wishing to be like one more rich in hope,
Featured like him, like him with friends possessed,
Desiring this man’s art, and that man’s scope:’

but we would still be our selves, to possess and enjoy all these, or we
would not give a doit for them. But, on this supposition, what in
truth should we be the better for them? It is not we, but another, that
would reap the benefit; and what do we care about that other? In
that case, the present owner might as well continue to enjoy them.
We should not be gainers by the change. If the meanest beggar who
crouches at a palace-gate, and looks up with awe and suppliant fear
to the proud inmate as he passes, could be put in possession of all the
finery, the pomp, the luxury, and wealth that he sees and envies on
the sole condition of getting rid, together with his rags and misery, of
all recollection that there ever was such a wretch as himself, he
would reject the proffered boon with scorn. He might be glad to
change situations; but he would insist on keeping his own thoughts,
to compare notes, and point the transition by the force of contrast.
He would not, on any account, forego his self-congratulation on the
unexpected accession of good fortune, and his escape from past
suffering. All that excites his cupidity, his envy, his repining or
despair, is the alternative of some great good to himself; and if, in
order to attain that object, he is to part with his own existence to take
that of another, he can feel no farther interest in it. This is the
language both of passion and reason.
Here lies ‘the rub that makes calamity of so long life:’ for it is not
barely the apprehension of the ills that ‘in that sleep of death may
come,’ but also our ignorance and indifference to the promised good,
that produces our repugnance and backwardness to quit the present
scene. No man, if he had his choice, would be the angel Gabriel to-
morrow! What is the angel Gabriel to him but a splendid vision? He
might as well have an ambition to be turned into a bright cloud, or a
particular star. The interpretation of which is, he can have no
sympathy with the angel Gabriel. Before he can be transformed into
so bright and ethereal an essence, he must necessarily ‘put off this
mortal coil’—be divested of all his old habits, passions, thoughts, and
feelings—to be endowed with other lofty and beatific attributes, of
which he has no notion; and, therefore, he would rather remain a
little longer in this mansion of clay, which, with all its flaws,
inconveniences, and perplexities, contains all that he has any real
knowledge of, or any affection for. When, indeed, he is about to quit
it in spite of himself, and has no other chance left to escape the
darkness of the tomb, he may then have no objection (making a
virtue of necessity) to put on angels’ wings, to have radiant locks, to
wear a wreath of amaranth, and thus to masquerade it in the skies.
It is an instance of the truth and beauty of the ancient mythology,
that the various transmutations it recounts are never voluntary, or of
favourable omen, but are interposed as a timely release to those who,
driven on by fate, and urged to the last extremity of fear or anguish,
are turned into a flower, a plant, an animal, a star, a precious stone,
or into some object that may inspire pity or mitigate our regret for
their misfortunes. Narcissus was transformed into a flower; Daphne
into a laurel; Arethusa into a fountain (by the favour of the gods)—
but not till no other remedy was left for their despair. It is a sort of
smiling cheat upon death, and graceful compromise with
annihilation. It is better to exist by proxy, in some softened type and
soothing allegory, than not at all—to breathe in a flower or shine in a
constellation, than to be utterly forgot; but no one would change his
natural condition (if he could help it) for that of a bird, an insect, a
beast, or a fish, however delightful their mode of existence, or
however enviable he might deem their lot compared to his own.
Their thoughts are not our thoughts—their happiness is not our
happiness; nor can we enter into it except with a passing smile of
approbation, or as a refinement of fancy. As the poet sings:—
‘What more felicity can fall to creature
Than to enjoy delight with liberty,
And to be lord of all the works of nature?
To reign in the air from earth to highest sky;
To feed on flowers and weeds of glorious feature;
To taste whatever thing doth please the eye?—
Who rests not pleased with such happiness,
Well worthy he to taste of wretchedness!’

This is gorgeous description and fine declamation: yet who would be


found to act upon it, even in the forming of a wish; or would not
rather be the thrall of wretchedness, than launch out (by the aid of
some magic spell) into all the delights of such a butterfly state of
existence? The French (if any people can) may be said to enjoy this
airy, heedless gaiety and unalloyed exuberance of satisfaction: yet
what Englishman would deliberately change with them? We would
sooner be miserable after our own fashion than happy after their’s. It
is not happiness, then, in the abstract, which we seek, that can be
addressed as
‘That something still that prompts th’ eternal sigh,
For which we wish to live or dare to die,—’

but a happiness suited to our taste and faculties—that has become a


part of ourselves, by habit and enjoyment—that is endeared to us by
a thousand recollections, privations, and sufferings. No one, then,
would willingly change his country or his kind for the most plausible
pretences held out to him. The most humiliating punishment
inflicted in ancient fable is the change of sex: not that it was any
degradation in itself—but that it must occasion a total derangement
of the moral economy and confusion of the sense of personal
propriety. The thing is said to have happened, au sens contraire, in
our time. The story is to be met with in ‘very choice Italian’; and Lord
D—— tells it in very plain English!
We may often find ourselves envying the possessions of others,
and sometimes inadvertently indulging a wish to change places with
them altogether; but our self-love soon discovers some excuse to be
off the bargain we were ready to strike, and retracts ‘vows made in
haste, as violent and void.’ We might make up our minds to the
alteration in every other particular; but, when it comes to the point,
there is sure to be some trait or feature of character in the object of
our admiration to which we cannot reconcile ourselves—some
favourite quality or darling foible of our own, with which we can by
no means resolve to part. The more enviable the situation of another,
the more entirely to our taste, the more reluctant we are to leave any
part of ourselves behind that would be so fully capable of
appreciating all the exquisiteness of its new situation, or not to enter
into the possession of such an imaginary reversion of good fortune
with all our previous inclinations and sentiments. The outward
circumstances were fine: they only wanted a soul to enjoy them, and
that soul is our’s (as the costly ring wants the peerless jewel to
perfect and set it off). The humble prayer and petition to sneak into
visionary felicity by personal adoption, or the surrender of our own
personal pretensions, always ends in a daring project of usurpation,
and a determination to expel the actual proprietor, and supply his
place so much more worthily with our own identity—not bating a
single jot of it. Thus, in passing through a fine collection of pictures,
who has not envied the privilege of visiting it every day, and wished
to be the owner? But the rising sigh is soon checked, and ‘the native
hue of emulation is sicklied o’er with the pale cast of thought,’ when
we come to ask ourselves not merely whether the owner has any taste
at all for these splendid works, and does not look upon them as so
much expensive furniture, like his chairs and tables—but whether he
has the same precise (and only true) taste that we have—whether he
has the very same favourites that we have—whether he may not be so
blind as to prefer a Vandyke to a Titian, a Ruysdael to a Claude;—
nay, whether he may not have other pursuits and avocations that
draw off his attention from the sole objects of our idolatry, and which
seem to us mere impertinences and waste of time? In that case, we at
once lose all patience, and exclaim indignantly, ‘Give us back our
taste and keep your pictures!’ It is not we who should envy them the
possession of the treasure, but they who should envy us the true and
exclusive enjoyment of it. A similar train of feeling seems to have
dictated Warton’s spirited Sonnet on visiting Wilton-House:—
‘From Pembroke’s princely dome, where mimic art
Decks with a magic hand the dazzling bowers,
Its living hues where the warm pencil pours,
And breathing forms from the rude marble start,
How to life’s humbler scene can I depart?
My breast all glowing from those gorgeous towers,
In my low cell how cheat the sullen hours?
Vain the complaint! For Fancy can impart
(To fate superior and to fortune’s power)
Whate’er adorns the stately storied-hall:
She, mid the dungeon’s solitary gloom,
Can dress the Graces in their attic pall;
Bid the green landskip’s vernal beauty bloom;
And in bright trophies clothe the twilight wall.’

One sometimes passes by a gentleman’s park, an old family-seat,


with its moss-grown ruinous paling, its ‘glades mild-opening to the
genial day,’ or embrowned with forest-trees. Here one would be glad
to spend one’s life, ‘shut up in measureless content,’ and to grow old
beneath ancestral oaks, instead of gaining a precarious, irksome, and
despised livelihood, by indulging romantic sentiments, and writing
disjointed descriptions of them. The thought has scarcely risen to the
lips, when we learn that the owner of so blissful a seclusion is a
thorough-bred fox-hunter, a preserver of the game, a brawling
electioneerer, a Tory member of parliament, a ‘no-Popery’ man!—‘I’d
sooner be a dog, and bay the moon!’ Who would be Sir Thomas
Lethbridge for his title and estate? asks one man. But would not
almost any one wish to be Sir Francis Burdett, the man of the people,
the idol of the electors of Westminster? says another. I can only
answer for myself. Respectable and honest as he is, there is
something in his white boots, and white breeches, and white coat,
and white hair, and red face, and white hat, that I cannot, by any
effort of candour, confound my personal identity with! If Mr.
Hobhouse can prevail on Sir Francis to exchange, let him do so by all
means. Perhaps they might contrive to club a soul between them!
Could I have had my will, I should have been born a lord: but one
would not be a booby lord neither. I am haunted by an odd fancy of
driving down the Great North Road in a chaise and four, about fifty
years ago, and coming to the inn at Ferry-bridge, with out-riders,
white favours, and a coronet on the panels; and then I choose my
companion in the coach. Really there is a witchcraft in all this that
makes it necessary to turn away from it, lest, in the conflict between
imagination and impossibility, I should grow feverish and light-
headed! But, on the other hand, if one was born a lord, should one
have the same idea (that every one else has) of a peeress in her own
right? Is not distance, giddy elevation, mysterious awe, an
impassable gulf, necessary to form this idea in the mind, that fine
ligament of ‘ethereal braid, sky-woven,’ that lets down heaven upon
earth, fair as enchantment, soft as Berenice’s hair, bright and
garlanded like Ariadne’s crown; and is it not better to have had this
idea all through life—to have caught but glimpses of it, to have
known it but in a dream—than to have been born a lord ten times
over, with twenty pampered menials at one’s back, and twenty
descents to boast of? It is the envy of certain privileges, the sharp
privations we have undergone, the cutting neglect we have met with
from the want of birth or title, that gives its zest to the distinction:
the thing itself may be indifferent or contemptible enough. It is the
becoming a lord that is to be desired; but he who becomes a lord in
reality is an upstart—a mere pretender, without the sterling essence;
so that, all that is of any worth in this supposed transition is purely
imaginary and impossible. Had I been a lord, I should have married
Miss ——, and my life would not have been one long-drawn sigh,
made up of sweet and bitter regret![41] Had I been a lord, I would
have been a Popish lord, and then I might also have been an honest
man:—poor, and then I might have been proud and not vulgar! Kings
are so accustomed to look down on all the rest of the world, that they
consider the condition of mortality as vile and intolerable, if stripped
of royal state, and cry out in the bitterness of their despair, ‘Give me
a crown, or a tomb!’ It should seem from this as if all mankind would
change with the first crowned head that could propose the
alternative, or that it would be only the presumption of the
supposition, or a sense of their own unworthiness, that would deter
them. Perhaps there is not a single throne that, if it was to be filled by
this sort of voluntary metempsychosis, would not remain empty.
Many would, no doubt, be glad to ‘monarchise, be feared, and kill
with looks’ in their own persons and after their own fashion: but who
would be the double of ——, or of those shadows of a shade—those
‘tenth transmitters of a foolish face’—Charles X. and Ferdinand VII.? If
monarchs have little sympathy with mankind, mankind have even
less with monarchs. They are merely to us a sort of state-puppets or
royal wax-work, which we may gaze at with superstitious wonder,
but have no wish to become; and he who should meditate such a
change must not only feel by anticipation an utter contempt for the
slough of humanity which he is prepared to cast, but must feel an
absolute void and want of attraction in those lofty and
incomprehensible sentiments which are to supply its place. With
respect to actual royalty, the spell is in a great measure broken. But,
among ancient monarchs, there is no one, I think, who envies Darius
or Xerxes. One has a different feeling with respect to Alexander or
Pyrrhus; but this is because they were great men as well as great
kings, and the soul is up in arms at the mention of their names as at
the sound of a trumpet. But as to all the rest—those ‘in the catalogue
who go for kings’—the praying, eating, drinking, dressing monarchs
of the earth, in time past or present—one would as soon think of
wishing to personate the Golden Calf, or to turn out with
Nebuchadnezzar to graze, as to be transformed into one of that
‘swinish multitude.’ There is no point of affinity. The extrinsic
circumstances are imposing: but, within, there is nothing but morbid
humours and proud flesh! Some persons might vote for
Charlemagne; and there are others who would have no objection to
be the modern Charlemagne, with all he inflicted and suffered, even
after the necromantic field of Waterloo, and the bloody wreath on the
vacant brow of his conqueror, and that fell jailer set over him by a
craven foe, that ‘glared round his soul, and mocked his closing
eyelids!’
It has been remarked, that could we at pleasure change our
situation in life, more persons would be found anxious to descend
than to ascend in the scale of society. One reason may be, that we
have it more in our power to do so; and this encourages the thought,
and makes it familiar to us. A second is, that we naturally wish to
throw off the cares of state, of fortune or business, that oppress us,
and to seek repose before we find it in the grave. A third reason is,
that, as we descend to common life, the pleasures are simple,
natural, such as all can enter into, and therefore excite a general
interest, and combine all suffrages. Of the different occupations of
life, none is beheld with a more pleasing emotion, or less aversion to
a change of our own, than that of a shepherd tending his flock: the
pastoral ages have been the envy and the theme of all succeeding
ones; and a beggar with his crutch is more closely allied than the
monarch and his crown to the associations of mirth and heart’s ease.
On the other hand, it must be admitted that our pride is too apt to
prefer grandeur to happiness; and that our passions make us envy
great vices oftener than great virtues.
The world shew their sense in nothing more than in a distrust and
aversion to those changes of situation which only tend to make the
successful candidates ridiculous, and which do not carry along with
them a mind adequate to the circumstances. The common people, in
this respect, are more shrewd and judicious than their superiors,
from feeling their own awkwardness and incapacity, and often
decline, with an instinctive modesty, the troublesome honours
intended for them. They do not overlook their original defects so
readily as others overlook their acquired advantages. It is wonderful,
therefore, that opera-singers and dancers refuse, or only condescend
as it were, to accept lords, though the latter are so often fascinated by
them. The fair performer knows (better than her unsuspecting
admirer) how little connection there is between the dazzling figure
she makes on the stage and that which she may make in private life,
and is in no hurry to convert ‘the drawing-room into a Green-room.’
The nobleman (supposing him not to be very wise) is astonished at
the miraculous powers of art in
‘The fair, the chaste, the inexpressive she;’

and thinks such a paragon must easily conform to the routine of


manners and society which every trifling woman of quality of his
acquaintance, from sixteen to sixty, goes through without effort. This
is a hasty or a wilful conclusion. Things of habit only come by habit,
and inspiration here avails nothing. A man of fortune who marries an
actress for her fine performance of tragedy, has been well compared
to the person who bought Punch. The lady is not unfrequently aware
of the inconsequentiality, and unwilling to be put on the shelf, and
hid in the nursery of some musty country-mansion. Servant girls, of
any sense and spirit, treat their masters (who make serious love to
them) with suitable contempt. What is it but a proposal to drag an
unmeaning trollop at his heels through life, to her own annoyance
and the ridicule of all his friends? No woman, I suspect, ever forgave
a man who raised her from a low condition in life (it is a perpetual
obligation and reproach); though, I believe, men often feel the most
disinterested regard for women under such circumstances. Sancho
Panza discovered no less folly in his eagerness to enter upon his new
government, than wisdom in quitting it as fast as possible. Why will
Mr. Cobbett persist in getting into Parliament? He would find
himself no longer the same man. What member of Parliament, I
should like to know, could write his Register? As a popular partisan,
he may (for aught I can say) be a match for the whole Honourable
House; but, by obtaining a seat in St. Stephen’s Chapel, he would
only be equal to a 576th part of it. It was surely a puerile ambition in
Mr. Addington to succeed Mr. Pitt as prime-minister. The situation
was only a foil to his imbecility. Gipsies have a fine faculty of evasion:
catch them who can in the same place or story twice! Take them;
teach them the comforts of civilization; confine them in warm rooms,
with thick carpets and down beds; and they will fly out of the
window-like the bird, described by Chaucer, out of its golden cage. I
maintain that there is no common language or medium of
understanding between people of education and without it—between
those who judge of things from books or from their senses. Ignorance
has so far the advantage over learning; for it can make an appeal to
you from what you know; but you cannot re-act upon it through that
which it is a perfect stranger to. Ignorance is, therefore, power. This
is what foiled Buonaparte in Spain and Russia. The people can only
be gained over by informing them, though they may be enslaved by
fraud or force. You say there is a common language in nature. They
see nature through their wants, while you look at it for your pleasure.
Ask a country lad if he does not like to hear the birds sing in the
spring? And he will laugh in your face. ‘What is it, then, he does
like?’—‘Good victuals and drink!’ As if you had not these too; but
because he has them not, he thinks of nothing else, and laughs at you
and your refinements, supposing you to live upon air. To those who
are deprived of every other advantage, even nature is a book sealed. I
have made this capital mistake all my life, in imagining that those
objects which lay open to all, and excited an interest merely from the
idea of them, spoke a common language to all; and that nature was a
kind of universal home, where all ages, sexes, classes met. Not so.
The vital air, the sky, the woods, the streams—all these go for
nothing, except with a favoured few. The poor are taken up with their
bodily wants—the rich, with external acquisitions: the one, with the
sense of property—the other, of its privation. Both have the same
distaste for sentiment. The genteel are the slaves of appearances—the
vulgar, of necessity; and neither has the smallest regard to true
worth, refinement, generosity. All savages are irreclaimable. I can
understand the Irish character better than the Scotch. I hate the
formal crust of circumstances and the mechanism of society. I have
been recommended, indeed, to settle down into some respectable
profession for life:—
‘Ah! why so soon the blossom tear?’

I am ‘in no haste to be venerable!’


In thinking of those one might wish to have been, many people will
exclaim, ‘Surely, you would like to have been Shakspeare?’ Would
Garrick have consented to the change? No, nor should he; for the
applause which he received, and on which he lived, was more
adapted to his genius and taste. If Garrick had agreed to be
Shakspeare, he would have made it a previous condition that he was
to be a better player. He would have insisted on taking some higher
part than Polonius or the Grave-digger. Ben Jonson and his
companions at the Mermaid would not have known their old friend
Will in his new disguise. The modern Roscius would have scouted
the halting player. He would have shrunk from the parts of the
inspired poet. If others were unlike us, we feel it as a presumption
and an impertinence to usurp their place; if they were like us, it
seems a work of supererogation. We are not to be cozened out of our
existence for nothing. It has been ingeniously urged, as an objection
to having been Milton, that ‘then we should not have had the
pleasure of reading Paradise Lost.’ Perhaps I should incline to draw
lots with Pope, but that he was deformed, and did not sufficiently
relish Milton and Shakspeare. As it is, we can enjoy his verses and
their’s too. Why, having these, need we ever be dissatisfied with
ourselves? Goldsmith is a person whom I considerably affect,
notwithstanding his blunders and his misfortunes. The author of the
Vicar of Wakefield, and of Retaliation, is one whose temper must
have had something eminently amiable, delightful, gay, and happy in
it.
‘A certain tender bloom his fame o’erspreads.’

But then I could never make up my mind to his preferring Rowe and
Dryden to the worthies of the Elizabethan age; nor could I, in like
manner, forgive Sir Joshua—whom I number among those whose
existence was marked with a white stone, and on whose tomb might
be inscribed ‘Thrice Fortunate!’—his treating Nicholas Poussin with
contempt. Differences in matters of taste and opinion are points of
honour—‘stuff o’ the conscience’—stumbling-blocks not to be got
over. Others, we easily grant, may have more wit, learning,
imagination, riches, strength, beauty, which we should be glad to
borrow of them; but that they have sounder or better views of things,
or that we should act wisely in changing in this respect, is what we
can by no means persuade ourselves. We may not be the lucky
possessors of what is best or most desirable; but our notion of what
is best and most desirable we will give up to no man by choice or
compulsion; and unless others (the greatest wits or brightest
geniuses) can come into our way of thinking, we must humbly beg
leave to remain as we are. A Calvinistic preacher would not
relinquish a single point of faith to be the Pope of Rome; nor would a
strict Unitarian acknowledge the mystery of the Holy Trinity to have
painted Raphael’s Assembly of the Just. In the range of ideal
excellence, we are distracted by variety and repelled by differences:
the imagination is fickle and fastidious, and requires a combination
of all possible qualifications, which never met. Habit alone is blind
and tenacious of the most homely advantages; and after running the
tempting round of nature, fame, and fortune, we wrap ourselves up
in our familiar recollections and humble pretensions—as the lark,
after long fluttering on sunny wing, sinks into its lowly bed!
We can have no very importunate craving, nor very great
confidence, in wishing to change characters, except with those with
whom we are intimately acquainted by their works; and having these
by us (which is all we know or covet in them), what would we have
more? We can have no more of a cat than her skin; nor of an author
than his brains. By becoming Shakspeare in reality, we cut ourselves
out of reading Milton, Pope, Dryden, and a thousand more—all of
whom we have in our possession, enjoy, and are, by turns, in the best
part of them, their thoughts, without any metamorphosis or miracle
at all. What a microcosm is our’s! What a Proteus is the human
mind! All that we know, think of, or can admire, in a manner
becomes ourselves. We are not (the meanest of us) a volume, but a
whole library! In this calculation of problematical contingencies, the
lapse of time makes no difference. One would as soon have been
Raphael as any modern artist. Twenty, thirty, or forty years of
elegant enjoyment and lofty feeling were as great a luxury in the
fifteenth as in the nineteenth century. But Raphael did not live to see
Claude, nor Titian Rembrandt. Those who found arts and sciences
are not witnesses of their accumulated results and benefits; nor in
general do they reap the meed of praise which is their due. We who
come after in some ‘laggard age,’ have more enjoyment of their fame
than they had. Who would have missed the sight of the Louvre in all
its glory to have been one of those whose works enriched it? Would it
not have been giving a certain good for an uncertain advantage? No:
I am as sure (if it is not presumption to say so) of what passed
through Raphael’s mind as of what passes through my own; and I
know the difference between seeing (though even that is a rare
privilege) and producing such perfection. At one time I was so
devoted to Rembrandt, that I think, if the Prince of Darkness had
made me the offer in some rash mood, I should have been tempted to
close with it, and should have become (in happy hour, and in
downright earnest) the great master of light and shade!
I have run myself out of my materials for this Essay, and want a
well-turned sentence or two to conclude with; like Benvenuto Cellini,
who complains that, with all the brass, tin, iron, and lead he could
muster in the house, his statue of Perseus was left imperfect, with a
dent in the heel of it. Once more then—I believe there is one
character that all the world would be glad to change with—which is
that of a favoured rival. Even hatred gives way to envy. We would be
any thing—a toad in a dungeon—to live upon her smile, which is our
all of earthly hope and happiness; nor can we, in our infatuation,
conceive that there is any difference of feeling on the subject, or that
the pressure of her hand is not in itself divine, making those to whom
such bliss is deigned like the Immortal Gods!
APHORISMS ON MAN

The Monthly Magazine.]


[October, 1830–June, 1831.

I
Servility is a sort of bastard envy. We heap our whole stock of
involuntary adulation on a single prominent figure, to have an excuse
for withdrawing our notice from all other claims (perhaps juster and
more galling ones), and in the hope of sharing a part of the applause
as train-bearers.
II
Admiration is catching by a certain sympathy. The vain admire the
vain; the morose are pleased with the morose; nay, the selfish and
cunning are charmed with the tricks and meanness of which they are
witnesses, and may be in turn the dupes.
III
Vanity is no proof of conceit. A vain man often accepts of praise as
a cheap substitute for his own good opinion. He may think more
highly of another, though he would be wounded to the quick if his
own circle thought so. He knows the worthlessness and hollowness
of the flattery to which he is accustomed, but his ear is tickled with
the sound; and the effeminate in this way can no more live without
the incense of applause, than the effeminate in another can live
without perfumes or any other customary indulgence of the senses.
Such people would rather have the applause of fools than the
approbation of the wise. It is a low and shallow ambition.
IV
It was said of some one who had contrived to make himself
popular abroad by getting into hot water, but who proved very
troublesome and ungrateful when he came home—‘We thought him a
very persecuted man in India’—the proper answer to which is, that
there are some people who are good for nothing else but to be
persecuted. They want some check to keep them in order.
V
It is a sort of gratuitous error in high life, that the poor are
naturally thieves and beggars, just as the latter conceive that the rich
are naturally proud and hard-hearted. Give a man who is starving a
thousand a-year, and he will be no longer under a temptation to get
himself hanged by stealing a leg of mutton for his dinner; he may still
spend it in gaming, drinking, and the other vices of a gentleman, and
not in charity, about which he before made such an outcry.
VI
Do not confer benefits in the expectation of meeting with
gratitude; and do not cease to confer them because you find those
whom you have served ungrateful. Do what you think fit and right to
please yourself; the generosity is not the less real, because it does not
meet with a correspondent return. A man should study to get
through the world as he gets through St. Giles’s—with as little
annoyance and interruption as possible from the shabbiness around
him.
VII
Common-place advisers and men of the world, are always
pestering you to conform to their maxims and modes, just like the
barkers in Monmouth-street, who stop the passengers by entreating
them to turn in and refit at their second-hand repositories.

You might also like