(Ebooks PDF) Download Python One Liners Write Concise Eloquent Python Like A Professional 1st Edition Christian Mayer Full Chapters
(Ebooks PDF) Download Python One Liners Write Concise Eloquent Python Like A Professional 1st Edition Christian Mayer Full Chapters
com
https://textbookfull.com/product/python-one-
liners-write-concise-eloquent-python-like-a-
professional-1st-edition-christian-mayer/
https://textbookfull.com/product/effective-python-90-specific-ways-to-
write-better-python-2nd-edition-brett-slatkin/
textbookfull.com
https://textbookfull.com/product/effective-python-90-specific-ways-to-
write-better-python-second-edition-brett-slatkin/
textbookfull.com
https://textbookfull.com/product/physical-properties-of-diamond-and-
sapphire-first-edition-aggarwal/
textbookfull.com
Animals in Victorian Literature and Culture: Contexts for
Criticism 1st Edition Laurence W. Mazzeno
https://textbookfull.com/product/animals-in-victorian-literature-and-
culture-contexts-for-criticism-1st-edition-laurence-w-mazzeno/
textbookfull.com
https://textbookfull.com/product/the-secret-of-the-nagas-the-shiva-
trilogy-book-2-2011th-edition-amish-tripathi/
textbookfull.com
https://textbookfull.com/product/routledge-handbook-of-international-
cybersecurity-eneken-tikk/
textbookfull.com
The Politics of Technology in Africa Iginio Gagliardone
https://textbookfull.com/product/the-politics-of-technology-in-africa-
iginio-gagliardone/
textbookfull.com
PYTHON
ONE-LINERS
W R I T E C O N C I S E , E L O Q U E N T P Y T H O N
L I K E A P R O F E S S I O N A L
CHRISTIAN MAYER
PYTHON ONE-LINERS
PY THON
ONE‑L INE RS
W r i t e C o n c i s e, E l o q u e n t
P y thon Like a Professional
by Christian M ayer
San Francisco
PYTHON ONE-LINERS. Copyright © 2020 by Christian Mayer.
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-10: 1-7185-0050-5
ISBN-13: 978-1-7185-0050-1
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; [email protected]
www.nostarch.com
The Library of Congress issued the following Cataloging-in-Publication Data for the first edition:
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 my wife Anna
About the Author
Christian Mayer is a doctor of computer science and the founder
and maintainer of the popular Python site https://blog.finxter.com/
and its associated newsletter, which has 20,000 active subscrib-
ers and is still growing. His rapidly growing websites help tens
of thousands of students improve their coding skills and online
businesses. Christian is also the author of the Coffee Break Python
series of self-published books.
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
CONTE NT S IN DE TA IL
ACKNOWLEDGMENTS xvii
INTRODUCTION xix
Python One-Liner Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
A Note on Readability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Who Is This Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
What Will You Learn? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
1
PYTHON REFRESHER 1
Basic Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Numerical Data Types and Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Keyword None . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Container Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
List and Set Comprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
if, else, and elif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Lambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2
PYTHON TRICKS 17
Using List Comprehension to Find Top Earners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Using List Comprehension to Find Words with High Information Value . . . . . . . . . . . . . . 21
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Reading a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Using Lambda and Map Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Using Slicing to Extract Matching Substring Environments . . . . . . . . . . . . . . . . . . . . . . 26
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Combining List Comprehension and Slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Using Slice Assignment to Correct Corrupted Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Analyzing Cardiac Health Data with List Concatenation . . . . . . . . . . . . . . . . . . . . . . . 33
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Using Generator Expressions to Find Companies That Pay Below Minimum Wage . . . . . 35
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Formatting Databases with the zip() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3
DATA SCIENCE 41
Basic Two-Dimensional Array Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Working with NumPy Arrays: Slicing, Broadcasting, and Array Types . . . . . . . . . . . . . . 46
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Conditional Array Search, Filtering, and Broadcasting to Detect Outliers . . . . . . . . . . . . 53
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
xii Contents In Detail
Boolean Indexing to Filter Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Broadcasting, Slice Assignment, and Reshaping to Clean Every i-th Array Element . . . . . 60
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
When to Use the sort() Function and When to Use the argsort() Function in NumPy . . . . . 64
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
How to Use Lambda Functions and Boolean Indexing to Filter Arrays . . . . . . . . . . . . . . 68
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
How to Create Advanced Array Filters with Statistics, Math, and Logic . . . . . . . . . . . . . 70
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Simple Association Analysis: People Who Bought X Also Bought Y . . . . . . . . . . . . . . . . 74
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Intermediate Association Analysis to Find Bestseller Bundles . . . . . . . . . . . . . . . . . . . . 77
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4
MACHINE LEARNING 81
The Basics of Supervised Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Training Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Inference Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Logistic Regression in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
K-Means Clustering in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
K-Nearest Neighbors in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Contents In Detail xiii
Neural Network Analysis in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Decision-Tree Learning in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Get Row with Minimal Variance in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Basic Statistics in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Classification with Support-Vector Machines in One Line . . . . . . . . . . . . . . . . . . . . . . 119
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Classification with Random Forests in One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
5
REGULAR EXPRESSIONS 127
Finding Basic Textual Patterns in Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Writing Your First Web Scraper with Regular Expressions . . . . . . . . . . . . . . . . . . . . . 132
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Analyzing Hyperlinks of HTML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Extracting Dollars from a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Finding Nonsecure HTTP URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
xiv Contents In Detail
Validating the Time Format of User Input, Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Validating Time Format of User Input, Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Duplicate Detection in Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Detecting Word Repetitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Modifying Regex Patterns in a Multiline String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6
ALGORITHMS 151
Finding Anagrams with Lambda Functions and Sorting . . . . . . . . . . . . . . . . . . . . . . . 152
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Finding Palindromes with Lambda Functions and Negative Slicing . . . . . . . . . . . . . . . 154
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Counting Permutations with Recursive Factorial Functions . . . . . . . . . . . . . . . . . . . . . . 156
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Finding the Levenshtein Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Calculating the Powerset by Using Functional Programming . . . . . . . . . . . . . . . . . . . . 162
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Caesar’s Cipher Encryption Using Advanced Indexing and List Comprehension . . . . . . 165
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Contents In Detail xv
Finding Prime Numbers with the Sieve of Eratosthenes . . . . . . . . . . . . . . . . . . . . . . . 168
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Calculating the Fibonacci Series with the reduce() Function . . . . . . . . . . . . . . . . . . . . 174
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
A Recursive Binary Search Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
A Recursive Quicksort Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
AFTERWORD 183
INDEX 185
xvi Contents In Detail
ACKNOWLEDGMENTS
The world doesn’t need more books; it needs better books. I’m incredibly
grateful to the people at No Starch Press for putting everything at work
toward this philosophy. This book is the result of their invaluable advice,
constructive feedback, and hundreds of hours of diligent work. My deep
gratitude goes to the No Starch team for making the book-writing process
such a fun experience.
In particular, I’d like to thank Bill Pollock for inviting me to write this
book and for providing me inspiration and deep insights into the publish-
ing world.
I’m very grateful for my brilliant content editor, Liz Chadwick, who
skillfully, patiently, and eloquently transformed my rough drafts into a
much more human-readable form. It’s because of her excellent support that
the book reached a level of clarity I would have never imagined when start-
ing this project.
I want to express my appreciation to Alex Freed for her relentless focus
on improving the text quality. It has been an honor to work together with
such a talented editor.
I’d like to thank my production editor, Janelle Ludowise, for polishing
the book with a great love for every detail. Janelle put her skills to work—in
a positive and enthusiastic manner—to craft the final version of the book.
Thanks, Janelle. Many thanks as well to Kassie Andreadis, who energetically
pushed the book through to completion.
My distinctive appreciation goes to Professor Daniel Zingaro. He didn’t
shy away from investing much of his time, effort, and excellent computer
science skills into eradicating inaccuracies from the book. He also contrib-
uted many wonderful suggestions that brought clarity to the book. Without
his effort, the book would not only contain more bugs but also be harder to
read. That said, any inaccuracies that remain are my own.
My doctorate supervisor, Professor Rothermel, contributed indirectly to
this book by investing considerable time, skill, and effort into my computer
science education. I owe him my deepest gratitude and appreciation.
I’m forever grateful to my beautiful wife, Anna Altimira, who keeps
listening to, encouraging, and supporting even my wildest ideas. I’m also
thankful to my kids, Amalie and Gabriel, for their inspiring curiosity and
the happiness they bring to my life through thousands of smiles.
Lastly, the greatest source of motivation came from the active members
of the Finxter community. First and foremost, I’ve written this book for
ambitious coders—like you—who want to advance their coding skills and
solve practical problems in the real world. After long working days, it was
grateful emails from Finxter members that encouraged me to write more
sections of the book.
xviii Acknowledgments
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
INTRODUCTION
q = lambda l: q( u[x for x in l[1:] if x <= l[0]]) + [l[0]] + q([x for x in l if x > l[0]]) if l else []
We can break this one-liner into even simpler one-liners that teach
important Python basics, such as variable assignments, math operators,
data structures, for loops, membership operators, and the range() func-
tion—all of which happens in a single line of Python!
xx Introduction
Know that basic doesn’t mean trivial. All the one-liners we’ll look at are
useful, and each chapter addresses a separate area or discipline in com-
puter science, giving you a broad perspective on the power of Python.
A Note on Readability
The Zen of Python comprises 19 guiding principles for the Python program-
ming languages. You can read it in your Python shell by entering import this:
# BEFORE
squares = []
for i in range(10):
squares.append(i**2)
print(squares)
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
In this code snippet, we need five lines of code to create a list of the
first 10 square numbers and print it to the shell. However, it’s much better
to use a one-liner solution that accomplishes the same thing in a more read-
able and concise way:
# AFTER
print([i**2 for i in range(10)])
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
The output is the same, but the one-liner builds on the more Pythonic
concept of list comprehension. It’s easier to read and more concise.
However, Python one-liners can also be hard to understand. In some
cases, writing a solution as a Python one-liner isn’t more readable. But just
as the chess master must know all possible moves before deciding which one
Introduction xxi
is best, you must know all ways of expressing your thoughts in code so that
you can decide on the best one. Going for the most beautiful solution is not
a low-priority matter; it’s at the core of the Python ecosystem. As The Zen of
Python teaches, “Beautiful is better than ugly.”
xxii Introduction
learn about how to calculate basic statistics of multidimensional data
arrays, and the K-Means algorithm for unsupervised learning. These
algorithms and methods are among the most important algorithms in
the field of machine learning.
Chapter 5: Regular Expressions Contains 10 one-liners to help you
achieve more with regular expressions. You’ll learn about various basic
regular expressions that you can combine (and recombine) in order to
create more-advanced regular expressions, using grouping and named
groups, negative lookaheads, escaped characters, whitespaces, character
sets (and negative characters sets), and greedy/nongreedy operators.
Chapter 6: Algorithms Contains 10 one-liner algorithms addressing
a wide range of computer science topics, including anagrams, palin-
dromes, supersets, permutations, factorials, prime numbers, Fibonacci
numbers, obfuscation, searching, and algorithmic sorting. Many of
these form the basis of more-advanced algorithms and contain the
seeds of a thorough algorithmic education.
Afterword Concludes this book and releases you into the real world,
packed with your new and improved Python coding skills.
Online Resources
To enhance the training material in this book, I’ve added supplementary
resources that you can find online at https://pythononeliners.com/ or http://www
.nostarch.com/pythononeliners/. The interactive resources include the following:
Python cheat sheets You can download those Python cheat sheets as
printable PDFs and pin them to your wall. The cheat sheets contain
essential Python language features, and if you study them thoroughly,
you can refresh your Python skills and ensure that you’ve closed any
knowledge gap you may have.
One-liner video lessons As part of my Python email course, I’ve
recorded many Python one-liner lessons from this book, which you can
access for free. Those lessons can assist you in your learning and pro-
vide a multimedia learning experience.
Python puzzles You can visit the online resources to solve Python puz-
zles and use the Finxter.com app for free to test and train your Python
skills and measure your learning progress as you go through the book.
Code files and Jupyter notebooks You must roll up your sleeves and
start working with code to make progress toward Python mastery. Take
your time to play around with various parameter values and input data.
For your convenience, I’ve added all Python one-liners as executable
code files.
Introduction xxiii
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Die
Frauenfrage im Mittelalter
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: German
VON
KARL BÜCHER.
T Ü B IN G E N
VERLAG DER H. L A U P P’SCHEN BUCHHANDLUNG
1910.
Alle Rechte vorbehalten.
GEWIDMET.
Das Beste, was Frauen uns geben, können wir niemals
wiedergeben, und wenn ich dieses Büchlein Dir, der lieben guten
Mama, zueigne, so weiss ich, dass damit die Dankesschuld nicht
abgetragen werden kann, zu der ich mich bekennen muss. Aber
vielleicht ist es Dir doch eine Freude, dadurch an die Zeit erinnert zu
werden, wo sich auf dem Frankfurter Stadtarchiv mir die Gedanken,
die es enthält, zusammenfügten und ich an so manchem schönen
Sonntag bei Euch in Heppenheim ausspannen durfte.
Ausgesprochen wurden diese Gedanken zuerst in einem Vortrage,
den ich am 28. März 1882 im Liebigschen Hörsaale zu München vor
gebildeten Frauen und Männern gehalten habe. Aus dem Kreise der
Zuhörer sahen damals zwei freundliche Augen zu mir empor, die
seitdem meinen Lebensweg erhellten und die jetzt erloschen sind.
Du wirst es vor allen verstehen, dass ich mich lange nicht
entschliessen konnte, das Büchlein, das damals gedruckt wurde, zu
erneuern, als es vergriffen war. Wenn ich es jetzt dennoch tue, so
bin ich nicht der Versuchung erlegen, was ich einst in keckem
Jugendmute hingestellt hatte, mit altem, bedächtigem Kopfe
umzumodeln. Die Schrift scheint doch manchem so, wie sie ist, lieb
geworden zu sein, und wenn ich heute vielleicht auch vieles anders
sagen würde, in ihren tatsächlichen Feststellungen hat sie vor der
Kritik bestehen können. Die Verbesserungen der neuen Auflage
beschränken sich deshalb auf kleinere Berichtigungen und Zusätze
und auf eine grössere Aenderung am Schlusse, zu der die Ergebnisse
der Berufszählung von 1907 Anlass gaben. Ausserdem sind in den
Anmerkungen einige genauere Belege gegeben, ohne dass
Vollständigkeit der Literaturangaben erstrebt wurde. Eine gelehrte
Abhandlung sollte mein Vortrag nicht werden.
Eine neue Zugabe ist das Bildchen auf Umschlag und Einband. Es
stellt eine der Hilfsarbeiterinnen des Frankfurter Wollenhandwerks,
wenn nicht alles trügt, in Bekinentracht dar, entworfen von einem
Frankfurter Schreiber, der das Bedebuch von 1405 mit lustigen
Federzeichnungen versehen hat. Das Bildchen steht bei der
Lindheimer Gasse, die im damaligen Weberviertel der Altstadt liegt.
Bei der Härte der mittelalterlichen Bede ist eine amtlich illustrierte
Steuerliste eine so seltsame Erscheinung, dass ihr Urheber
wenigstens in einer kleinen Probe seiner Kunst dem steuergeplagten
XX. Jahrhundert bekannt zu werden verdiente, stünde diese Probe
auch nicht in so enger Beziehung zum Inhalt dieses Büchleins, als es
tatsächlich der Fall ist. Vielleicht kann sie seinen Ernst um ein
Weniges mildern und durch ihr Wirklichkeitsgepräge den Irrtümern,
deren es immer noch genug enthalten wird, die freundliche
Nachsicht erwirken, deren wir alle bedürfen.
K a r l B ü c h e r.
I n h a l t.
Die Frage 1. — Ihr zwiespältiges Wesen 2. — Ihre
statistische Wurzel 3. — Das Zahlenverhältnis der
Geschlechter im Mittelalter 5. — Ursachen des grossen
Frauenüberschusses 7. Verschärfung durch
Ehebeschränkungen 9. — Wirtschaftliche Stellung der Frau im
deutschen Altertum 10. — Berufsbildung und Entlastung der
Frauen 12. — Angeblicher Ausschluss von zünftiger
Erwerbstätigkeit 13. — Tatsächliches Verhältnis 15, — in der
Textilindustrie 16, in der Schneiderei 18, — in anderen
zünftigen Gewerben 19, — in nicht zünftigen Berufen 20. —
Versorgungsanstalten: a) Klöster 24; — b) Leibrentenkauf 26;
— c) Samenungen 27; — d) Gotteshäuser 32. Statistisches
34. Statuten 35. Tätigkeit der Bekinen 36.
Aufnahmebedingungen 38. Lebensweise 38. Religiöse
Stellung 40. Entartung 41. — Soziale Stellung der Frauen im
Mittelalter 43. — Gegensätze 45. — Fahrende Frauen 48. —
Die gemeinen Frauen in den Städten 55. Frauenhäuser 56.
Sittenpolizei 60. Eingreifen der Kirche 61. Reuerinnen 62.
Rettungshäuser 63. — Rückblick 66. Wandlung seit der
Reformation 67. — Die heutige Frauenfrage 71. —
Anmerkungen 76.
D ie »Frauenfrage« bildet nach allgemeiner Annahme eine
Zeitfrage von so eigenartig modernem Charakter, dass es von
vornherein fraglich erscheinen könnte, ob man berechtigt sei,
diesen Ausdruck auch auf Erscheinungen der Vergangenheit
anzuwenden. Wenn wir aber überall da von »Fragen« reden, wo wir
die vorhandenen Zustände in einem auffälligen Widerspruche sehen
zu dem, was Vernunft und Gerechtigkeit fordern, so wird es wohl
kaum noch einem Zweifel unterliegen, dass wir auch von Fragen der
Vergangenheit sprechen dürfen, wo wir immer derartige
Widersprüche zwischen dem, was w a r, und dem, was hätte sein
sollen, entdecken. Es ist dabei ziemlich gleichgültig, ob die
tatsächlich vorhandenen Widersprüche als »Fragen« in das
Bewusstsein der Zeitgenossen getreten sind; es genügt vollständig,
wenn ein derartiger Widerspruch nachgewiesen werden kann, oder
wenn sich Versuche und Anstalten zu seiner Beseitigung erkennen
lassen. Oder wollte etwa jemand leugnen, dass die moderne
Frauenfrage lange vor der Zeit schon existiert hat, wo sie anfing, in
populären Vorträgen, auf »Frauentagen« oder bei ästhetischen
Teegesellschaften verhandelt zu werden?
Hier wirft sich zunächst die Frage auf: woher kommt dieser
bedeutende Ueberschuss der erwachsenen weiblichen über die
männliche Bevölkerung? Ich will versuchen, dieselbe mit ein paar
kurzen Andeutungen zu beantworten. Drei Ursachen scheinen mir
besonders in Betracht zu kommen:
1. die zahlreichen Bedrohungen, welchen das männliche Leben in
den mittelalterlichen Städten infolge der fortwährenden Fehden, der
blutigen Bürgerzwiste und der gefahrvollen Handelsreisen ausgesetzt
war;
2. die grössere Sterblichkeit der Männer bei den oft sich
wiederholenden pestartigen Krankheiten. Mindestens weisen auf
eine derartige Vermutung hin die stärkeren Ziffern für die Frauen,
welche regelmässig nach Pestjahren in den Frankfurter Steuerlisten
auftreten[3];
3. die Unmässigkeit der Männer in jeder Art von Genuss.
Ausserdem ist wohl die Vermutung nicht abzuweisen, dass die
städtische Berufsarbeit in engen, ungesunden Räumen, zwischen
hohen, dicht zusammengerückten Häusermauern bei der
Unvollkommenheit der technischen Hilfsmittel viel mehr aufreibende
Muskelarbeit von den Männern erfordert habe, dass der
Daseinskampf bei dem raschen Wechsel von guten und schlechten
Jahren, von hohen und niederen Lebensmittelpreisen, von
Ueberfluss und Mangel für sie, wenn auch vielleicht im ganzen nicht
schwieriger, so doch unregelmässiger und wechselvoller sich
gestaltet haben müsse als in Zeiten besserer Gesundheitspflege und
ausgebildeten nationalen und internationalen Verkehrs.
Welcher von diesen Entstehungsursachen nun auch der
mittelalterliche Frauenüberschuss vorwiegend zuzuschreiben sein
mag — sicher ist, dass er vorhanden war und dass er in mancherlei
Verhältnissen des sozialen Lebens seinen Ausdruck fand. Sicher ist
auch, dass die dadurch für zahlreiche Frauen gegebene
Unmöglichkeit einer Versorgung in der Ehe zu Uebelständen führte,
die das Mittelalter klar erkannte und auf seine eigene Art zu heilen
suchte.
In der Tat wird sich nicht leugnen lassen, dass die gesamte
Stellung der Gewerbe im Mittelalter ein selbständiges Eingreifen der
Frauen in dieses Gebiet grundsätzlich auszuschliessen scheint. Das
Zunftwesen, welchem alle einigermassen entwickelten Gewerbe
unterworfen waren, war seinem innersten Wesen nach auf die
Familie gegründet. Die Zünfte waren nicht bloss gewerbliche
Vereine, sondern Unterabteilungen der Gemeinde mit rechtlichen,
politischen, militärischen und administrativen Aufgaben. Das Recht
zum Gewerbebetrieb schloss die Verpflichtung zum Waffendienst und
zu anderen Leistungen in sich, zu welchen Frauen nicht wohl
herangezogen werden konnten. Bei der Teilnahme an den politischen
Rechten, von der ja die Frauen ausgeschlossen waren, spielten die
Zünfte wieder eine Rolle, welche die Zulassung weiblicher Mitglieder
untunlich zu machen schien.
Adrian Beier[9], der Verfasser des ältesten Kompendiums des
Handwerksrechts, stellt denn auch den Satz auf: das männliche
Geschlecht sei eine der unerlässlichen Grundbedingungen für die
Aufnahme in eine Zunft gewesen. Die ganze gesellschaftliche
Ordnung, meint er, beruhe darauf, dass jedes Geschlecht diejenigen
Geschäfte übernehme, welche seiner Natur am angemessensten
seien, der Mann die Erwerbsarbeit, die Frau die Küche, den
Spinnrocken, die Nadel, die Wäsche; auch das Weben,
Lichtergiessen und Seifensieden solle ihr noch gestattet sein. Das
Mädchen sei zur Ehe bestimmt; man könne nicht wissen, wen es
einmal heiraten werde; eine gelernte Schusterin sei aber dem
Schmiede nichts nütze. Ausserdem könne man nicht allein in der
Lehre lernen; von ungewanderten Junggesellen und gewanderten
Jungfern werde aber beiderseits wenig gehalten. Der Umgang mit
Männern in der Werkstätte sei in sittlicher Hinsicht nicht
ungefährlich. Endlich sei die Zunft eine öffentliche Einrichtung; das
Meisterrecht sei mit staatlichen Leistungen, als Wachen und Gaffen,
verbunden, wozu Weiber nicht taugten.