Coffee Break Python Workbook
Coffee Break Python Workbook
127 Python Puzzles to Push You from Zero to Hero in Your Coffee Breaks
About the Book
Puzzle-based Learning Python
This book is the chess grandmaster way of learning Python. It offers you 127 unique and brand-new Python puzzles. Every puzzle points to gaps in your knowledge, challenges you to guess a solution, and then explains potential solutions, in an easy-to-understand manner:
~~~
# Here’s one example puzzle:
my_list = [1, 1, 1, 1]
my_list[1::2] = [2, 3]
print(my_list)
# What’s the output of this code snippet?
~~~
An easy, fun, and effective way of learning Python -- day after day -- in your COFFEE BREAK PYTHON!
Here's what research says about puzzle-based learning:
"Students who were quizzed after studying a short text could recall significantly more information than students who were asked to reread it"
-- Karpicke, 2007, Elsevier Journal of Memory and Language
Practice testing is scientifically proven to generate up to 44% better learning retention and efficiency.
Simply put: quizzes and puzzles work! More than 100,000 Finxters and thousands of "Coffee Break Python" book customers have already successfully improved their skills with code puzzles.
Learning does not happen in a linear and orderly manner. It's a probabilistic, chaotic, and iterative process of creating knowledge gaps in your brain -- and filling them with just the right information you need.
That's the premise of the "Coffee Break Python" textbook series.
What will you get out of the book?
- Improve your level of deep Python code understanding.
- Surprise your peers with your newly acquired code speed reading skills.
- Enjoy the small daily doses of intellectual challenges. A Finxter once called it "Sudoku for coders"! ;)
- Improve your brain's working memory by hammering down the most important concepts.
- Learn all the basic Python syntax elements.
- Discover your own skill level by tracking your puzzle-solving performance.
- Compare your skill level against other coders: are you a grandmaster of code?
- Enjoy the fun of rushing over Python -- from "hello world" to "recursive Quicksort".
- Get the best of all Finxter Python cheat sheets to revive 80% of the Python features in 20% of the time.
- Get your dream job and rock future code interviews!
And take one step forward mastering the most popular programming language ON THE PLANET!
Bundles that include this book
Reader Testimonials

Vlad Bezden, Software engineer
I love it!
Thank you. I love it :) I enjoy reading this book! Keep up the good work.

Albrecht, German Workbook Reader
Great Book!
"A great book, I've learned a lot and marked every knowledge gap [...] Thank you very much!"
Table of Contents
1 Introduction 1
2 A Case for Puzzle-based Learning 5
2.1 Overcome the Knowledge Gap . . . . . . . 6
2.2 Embrace the Eureka Moment . . . . . . . 7
2.3 Divide and Conquer . . . . . . . . . . . . 8
2.4 Improve From Immediate Feedback . . . . 9
2.5 Measure Your Skills . . . . . . . . . . . . . 10
2.6 Individualized Learning . . . . . . . . . . . 12
2.7 Small is Beautiful . . . . . . . . . . . . . . 12
2.8 Active Beats Passive Learning . . . . . . . 14
2.9 Make Code a First-class Citizen . . . . . . 16
2.10 What You See is All There is . . . . . . . 18
3 The Elo Rating for Python 21
3.1 How to Use This Book . . . . . . . . . . . 21
3.2 How to Test and Train Your Skills? . . . . 23
3.3 What Can This Book Do For You? . . . . 27
4 A Quick Overview of the Python Language 31
4.1 Keywords . . . . . . . . . . . . . . . . . . 32
4.2 Basic Data Types . . . . . . . . . . . . . . 35
4.3 Complex Data Types . . . . . . . . . . . . 38
4.4 Classes . . . . . . . . . . . . . . . . . . . . 43
4.5 Functions and Tricks . . . . . . . . . . . . 46
5 Puzzles: Basic to Scholar 51
5.1 Printing values . . . . . . . . . . . . . . . 51
5.2 Basics of variables . . . . . . . . . . . . . . 53
5.3 Getting started with strings . . . . . . . . 54
5.4 Types of variables I . . . . . . . . . . . . . 55
5.5 Types of Variables II . . . . . . . . . . . . 56
5.6 Minimum . . . . . . . . . . . . . . . . . . 57
5.7 String Concatenation . . . . . . . . . . . . 58
5.8 Line Breaks I . . . . . . . . . . . . . . . . 59
5.9 Line Breaks II . . . . . . . . . . . . . . . . 60
5.10 List Length . . . . . . . . . . . . . . . . . 61
5.11 Comparison Operators I . . . . . . . . . . 62
5.12 Comparison Operators II . . . . . . . . . . 63
5.13 Multiple Initializations . . . . . . . . . . . 64
6 Puzzles: Scholar to Intermediate 67
6.1 Maximum . . . . . . . . . . . . . . . . . . 67
6.2 Memory addresses . . . . . . . . . . . . . . 68
6.3 Swapping Values . . . . . . . . . . . . . . 69
6.4 The Boolean Operator AND . . . . . . . . 70
6.5 The Boolean Operator OR . . . . . . . . . 72
6.6 Boolean Operators . . . . . . . . . . . . . 74
6.7 Arithmetic Expressions . . . . . . . . . . . 76
6.8 Integer Division and Modulo . . . . . . . . 78
6.9 Building Strings . . . . . . . . . . . . . . . 80
6.10 The len() Function . . . . . . . . . . . . 81
6.11 String Indices . . . . . . . . . . . . . . . . 82
6.12 The upper() Function . . . . . . . . . . . . 83
6.13 The lower() Function . . . . . . . . . . . . 84
6.14 Somebody Is Shouting . . . . . . . . . . . 85
6.15 Counting Characters . . . . . . . . . . . . 86
6.16 String Lengths . . . . . . . . . . . . . . . 87
6.17 Finding Characters in Strings . . . . . . . 88
6.18 Not Finding Characters in Strings . . . . . 89
6.19 Counting Letters . . . . . . . . . . . . . . 90
6.20 Min() and Max() of a String . . . . . . . . 91
6.21 Reversed Strings . . . . . . . . . . . . . . 92
6.22 String Equality . . . . . . . . . . . . . . . 93
6.23 Slicing I . . . . . . . . . . . . . . . . . . . 95
6.24 Slicing II . . . . . . . . . . . . . . . . . . . 96
6.25 Slicing III . . . . . . . . . . . . . . . . . . 97
6.26 Slicing IV . . . . . . . . . . . . . . . . . . 98
6.27 Slicing V . . . . . . . . . . . . . . . . . . . 99
6.28 Memory Addresses and Slicing . . . . . . . 100
6.29 Accessing List Items I . . . . . . . . . . . 101
6.30 Accessing List Items II . . . . . . . . . . . 103
6.31 List as Stack . . . . . . . . . . . . . . . . . 104
6.32 More String Operations . . . . . . . . . . 105
6.33 Checking for Substrings . . . . . . . . . . 106
6.34 Stripping String Boundaries . . . . . . . . 107
6.35 Strings: Stripping vs. Replacement . . . . 108
6.36 Glueing Strings Together . . . . . . . . . . 109
6.37 The Copy Operation . . . . . . . . . . . . 110
6.38 Growing List Contents I . . . . . . . . . . 111
6.39 Growing List Contents II . . . . . . . . . . 112
6.40 List Operations I . . . . . . . . . . . . . . 114
6.41 List Operations II . . . . . . . . . . . . . . 115
6.42 List Operations III . . . . . . . . . . . . . 116
6.43 List Operations IV . . . . . . . . . . . . . 117
6.44 List Operations V . . . . . . . . . . . . . . 117
6.45 List Operations VI . . . . . . . . . . . . . 118
6.46 List Operations VII . . . . . . . . . . . . . 119
6.47 List Operations VIII . . . . . . . . . . . . 120
6.48 List Operations IX . . . . . . . . . . . . . 121
6.49 List Operations X . . . . . . . . . . . . . . 122
6.50 Lists and the Range Function I . . . . . . 123
6.51 Lists and the Range Function II . . . . . . 124
6.52 Lists and the Range Function III . . . . . 125
6.53 Python’s Multiple Assignment I . . . . . . 126
6.54 Slice Assignments . . . . . . . . . . . . . . 127
6.55 Strings and Lists II . . . . . . . . . . . . . 128
6.56 String Comparisons . . . . . . . . . . . . . 129
6.57 From Booleans to Strings . . . . . . . . . . 130
6.58 Boolean Trickery I . . . . . . . . . . . . . 131
6.59 Boolean Trickery II . . . . . . . . . . . . . 132
6.60 Boolean Trickery III . . . . . . . . . . . . 133
6.61 Looping over Ranges . . . . . . . . . . . . 134
6.62 Reversed Loops . . . . . . . . . . . . . . . 135
6.63 Boolean Trickery IV . . . . . . . . . . . . 136
6.64 Lists and Memory Addresses . . . . . . . . 137
6.65 List Objects . . . . . . . . . . . . . . . . . 138
6.66 Boolean Tricks . . . . . . . . . . . . . . . 139
6.67 Complex Numbers . . . . . . . . . . . . . 140
6.68 Tuples . . . . . . . . . . . . . . . . . . . . 141
6.69 Multiple Assignments . . . . . . . . . . . . 142
6.70 Boolean Integer Conversion . . . . . . . . 143
6.71 The any() Function . . . . . . . . . . . . 144
6.72 The sum() Function . . . . . . . . . . . . 146
6.73 Accessing Complex Numbers . . . . . . . . 148
6.74 Tuple Confusion . . . . . . . . . . . . . . . 149
6.75 Understanding While ... Else (1/3) . . . . 150
6.76 Understanding While ... Else (2/3) . . . . 151
6.77 Understanding While ... Else (3/3) . . . . 153
6.78 Basic Arithmetic . . . . . . . . . . . . . . 155
6.79 Dictionary . . . . . . . . . . . . . . . . . . 156
6.80 Dictionary of Dictionaries . . . . . . . . . 158
6.81 Reverse Dictionary Index . . . . . . . . . . 160
6.82 Default Arguments . . . . . . . . . . . . . 162
7 Puzzles: Intermediate to Professional 165
7.1 Building Strings II . . . . . . . . . . . . . 165
7.2 String: Slicing and Indexing . . . . . . . . 167
7.3 Built-in Python Operations . . . . . . . . 168
7.4 Strings and Lists I . . . . . . . . . . . . . 169
7.5 Formatting Printouts . . . . . . . . . . . . 170
7.6 Floating Point Comparisons . . . . . . . . 172
7.7 Python’s Multiple Assignment II . . . . . 174
7.8 The Not-So-Obvious Case . . . . . . . . . 175
7.9 Rounding Values . . . . . . . . . . . . . . 176
7.10 Initializing Integers . . . . . . . . . . . . . 177
7.11 Basic Typing . . . . . . . . . . . . . . . . 178
7.12 Short Circuiting . . . . . . . . . . . . . . . 179
7.13 While Arithmetic . . . . . . . . . . . . . . 182
7.14 The Lambda Function . . . . . . . . . . . 183
7.15 Zip . . . . . . . . . . . . . . . . . . . . . . 184
7.16 Basic Filtering . . . . . . . . . . . . . . . . 186
7.17 List Comprehension . . . . . . . . . . . . . 188
7.18 Encryption by Obfuscation . . . . . . . . . 190
7.19 String Dictionary . . . . . . . . . . . . . . 193
7.20 Lambda Function . . . . . . . . . . . . . . 194
7.21 Dictionary of Dictionaries . . . . . . . . . 196
7.22 Sorting Dictionary Keys . . . . . . . . . . 198
7.23 Pythonic Loop Iteration . . . . . . . . . . 200
7.24 Filtering with List Comprehension . . . . . 202
7.25 Aggregating with List Comprehension . . . 204
7.26 Maximum of Tuples . . . . . . . . . . . . . 206
7.27 The Key Argument . . . . . . . . . . . . . 208
7.28 Puzzle 123 . . . . . . . . . . . . . . . . . . 210
7.29 Set Operations (1/2) . . . . . . . . . . . . 211
7.30 Set Operations (2/2) . . . . . . . . . . . . 212
7.31 Recursive Algorithm . . . . . . . . . . . . 214
7.32 Fibonacci . . . . . . . . . . . . . . . . . . 218
8 Final Remarks 221
Your skill level . . . . . . . . . . . . . . . 221
Where to go from here? . . . . . . . . . . 222
Other books by these authors
Authors have earned$10,253,953writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
500 QUIZ MMG COMMENTATI
ALS Medicina Generale500 Quiz degli ULTIMI Concorsi di Medicina Generale (2014/2016/2017/2018/2019)
Riassunti e suddivisi per area con Griglia risposte vuota e Griglia risposte esatte Ministeriale
Commentati con link alla fonte per approfondimento e ausilio allo studio
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Algebra-Driven Design
Sandy MaguireA how-to field guide on building leak-free abstractions and algebraically designing real-world applications.
Thinking with Types
Sandy MaguireThis book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #4
Cloud Architect: Transform Technology and Organization
2 Books
Architects don't just recite product names and features. They understand the options, decisions, and trade-offs behind them. They earn credibility and maintain authenticity by connecting the penthouse with the engine room. Get two essential books that redefine the role of the software and IT architect at one low price:37 Things One Architect... - #6
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #7
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming... - #10
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...