Python_21_Sample_Codes_And_Advance_Crash_Course_Guide_In_Python
Python_21_Sample_Codes_And_Advance_Crash_Course_Guide_In_Python
This declaration is deemed fair and valid by both the American Bar Association
and the Committee of Publishers Association and is legally binding throughout
the United States.
This is not a beginner’s book. It assumes that you are comfortable using Python,
the command line, and any text editor of your choice. All examples covered in
this book use Python3 so make sure you set up your environment accordingly.
Chapter 1 will begin with a few abstract data types and how to implement them.
These include the binary search tree and nth-dimensional tree. Additionally, you
will learn about the A* star pathfinding algorithm and how abstract data types
play a role in its execution
Chapter 2 will give an example of Binary arithmetic using a Python class along
with an introduction to unit testing your code. Chapter 3 is a poker-hand
evaluator that you can extend to a full-blown poker game.
Chapter 4 provides utility functions for reading eBook data and Chapter 5
teaches you how to write a simple command line game.
Chapter 6 extends further, showing you how to make graphical games using the
Pygame library.
Next, in chapter eight, you will learn how to create desktop apps using the
Tkinter library.
Chapter 9 is a brief introduction to data science, and finally, chapter ten will
teach you the basics of web development with Python and how to set up Python
web servers.
There are plenty of books on this subject on the market, so thanks again for
choosing this one! Every effort was made to ensure it is full of as much useful
information and code samples as possible. Please enjoy!
Chapter 1: Data Structures and the A* Algorithm
In this chapter, you will learn how to create abstract data structures using the
same Python data types you already know. Abstract data structures allow your
programs to process data in intuitive ways and rely on the Don’t Repeat Yourself
(DRY) principle. That is, using less code, and not typing out the same operations
repeatedly for each case. As you study the examples given, you will begin to
notice a pattern emerging: the use of classes that complement each other with
one acting as a node and another as a container of nodes. In computer science, a
data structure that uses nodes is generally referred to as a tree. There are many
different types of trees, each with specialized use cases. You may have already
heard of binary trees if you are interested in programming or computer science at
all.
One possible type of tree is called an n-ary tree, or n-dimensional tree. Unlike
the binary tree, the n-ary tree contains nodes that have an arbitrary number of
children. A child is simply another instance of a node that is linked to another
node, sometimes called a parent. The parent must have some mechanism for
linking up to child nodes. The easiest way to do this is with a list of objects.
Example Coding #1: A Mock File-System
A natural application of the n-ary tree is a traditional windows or UNIX file
system. Nodes can be either folders, directories or individual files. To keep
things simple the following program assumes a single directory as the tree’s root.
# ch1a.py
The FileSystem acts as the tree, and the Node class does most of the work,
which is common with tree data structures. Notice also that FileSystem keeps
track of individual ID’s for each node. The ID’s can be used as a way to quantify
the number of nodes in the file system or to provide lookup functionality.
When it comes to trees, the most onerous task is usually programming a solution
for traversal. The usual way a tree is structured is with a single node as a root,
and from that single node, the rest of the tree can be accessed. Here the function
look_up_parent uses a loop to traverse the mock directory structure, but it can
easily be adapted to a recursive solution as well.
General usage of the program is as follows: initiate the FileSystem class, declare
Node objects with the directory syntax (in this case backslash so Python won’t
mistake it for escape characters), and then calling the add method on them.
Example Coding # 2: Binary Search Tree (BST)
The binary search tree gets its name from the fact that a node can contain at most
two children. While this may sound like a restriction, it is actually a good one
because the tree becomes intuitive to traverse. An n-ary tree, in contrast, can be
messy.
# ch1b.py
As before, the Node class does most of the heavy lifting. This program uses a
BST primarily to sort a list of numbers but can be generalized to sorting any data
type. There are also a number of auxiliary methods for finding out the size of the
tree and which nodes are childless (leaves).
This implementation of a tree better illustrates the role that recursion takes when
traversing a tree at each node calls a method (for example insert) and creates a
chain until a base case is reached.
Example Coding # 3: A* Algorithm
The A* star search algorithm is considered the same as the Dijkstra algorithm
but with brains. Whereas Dijkstra searches almost exhaustedly until the path is
found, A* uses what is called a heuristic, which is a fancy way of saying
“educated guess.” A* is fast because it is able to point an arrow at the target
(using the heuristic) and find steps on that path.
After the first node is added to the heap, each neighbor node will be evaluated
for distance and the closest one to B is added to the heap. The process repeats
until the node is equal to B.
#ch1c.py
In this case, the heuristic is called Manhattan distance, which is just the absolute
value between the current node and the target. The heapq library is being used to
create a priority queue with f as the priority. Note that the backtrace function is
simply traversing a tree of nodes that each has a single parent.
You can think of the g variable is the cost of moving from the starting point to
somewhere along the path. Since we are using a grid with no variation in
movement cost g can be constant. The h variable is the estimated distance
between the current node and the target. Adding these two together gives you the
f variable, which is what controls the order of nodes on the path.
Documentation
Heapq: https://docs.Python.org/2/library/heapq.html
Chapter 2: Binary Arithmetic
It is important to test your code every now and then. The program on the
following page was used to make sure that the Binary class worked as intended.
The unittest module comes with the standard library so there is no need to install
via pip. To use it simply define a class that inherits from unittest.TestCase that
includes the setup() method as well as any additional methods you want to be
tested. Whenever you test code, there needs to be a clear result so that calling the
assert functions don’t return false positives.
Extensions for Chapter 2
1. Implement the __abs__ and __lt__ methods for the Binary class (note
that there is a class decorator from the functools module named
functools.total_ordering that implements the other comparison
operators if you define __eq__ and __lt__.
2. Run the tests until you get 100% completion
3. Division and multiplication are just extensions of subtracting and
adding. See if you can implement __mul__ and __div__
Documentation
Two’s complement: https://en.wikipedia.org/wiki/Two%27s_complement
Unittest: https://docs.Python.org/3/library/unittest.html
Functools: https://docs.Python.org/3/library/functools.html
Chapter 3: Poker Hand Evaluator
Poker is a card game that uses a standard deck and five card hands. If you
abstract a hand into some data structure, it is easy to evaluate it for hand
strength. The following program uses the BitArray class from the bitstring
library to represent hands.
A hand is 64-bit data type made up of four 16-bit words. Each word represents a
suit, and each bit represents a card rank from left to right (only 13 of these bits
will be used as there are only 13 different ranks, resulting in 3 empty leading
bits)
Each hand has a calculable value, implemented in a 32-bit data type made up of
8 4-bit words. Two words are empty, followed by one word indicating hand-type,
followed by 5 words representing a hand. The hexadecimal value of this data
type will be used to compare two hands, such that the higher the hexadecimal
value the higher the hand strength.
Checking for hand-type follows a set of functions based on the number of ranks.
A number of ranks is important because they implicate certain hand-types (4
unique ranks in a hand of 5 cards means that there is at least a pair). A hand-type
corresponds to a poker had (one pair, three of a kind, straight, etc.). The lowest
hand-type being 0 for high card and the highest being 9 for a royal flush.
Checking for flushes is a bit trickier. Instead of calling a function that returns
True or False, flushes are stored in a pre-computed lookup table. Remember that
in our hand data-type each suit is represented by a 16-bit word of possible ranks
(three of these are never used). Generating flushes is a matter of generating the
possible ways that one 13-bit word can have 5 bits turned on (five cards in one
suit is a flush). Straight flushes are determined by a string of 5 bits turned on in a
row, and royal flushes are determined by a string of 5 bits turned on descending
from the 13th bit. The lookup table is implemented with strings and a dictionary
key pointing to a hand-type.
In certain types of poker games, ties are dealt with by splitting the pot. Other
times the strength of remaining cards besides the significant ones (kickers) are
used to determine the stronger hand. This program uses kickers to determine
strength but ignores suit. Sometimes suits are given a strength in order to break
ties where hands and kickers are identical. For example, a royal flush of
diamonds is inferior to a royal flush of spades. This program, however, has all
royal flushes being of equal strength, since only kickers are used to break ties in
the final hand value calculation.
Extensions for Chapter 3
1. Using the unittest module write tests for a few different hand-types
and see if the program fails. If it does, find out why and fix it.
2. Implement tie-breaking functionality by taking into account strength
for ranks
3. Integrate the program into a two-player game, or a video-poker
application using the Tkinter library. (See chapter 8)
Documentation
Bitstring: https://pypi.org/project/bitstring/
Itertools: https://docs.Python.org/3/library/itertools.html
Chapter 4: Extracting Data from eBooks
Mining text from eBook formats is often difficult to code from scratch.
Thankfully, there exists a number of Python libraries designed to do just that.
The ones used in this chapter are PyPDF2 and epub, both easily installable with
pip. As far as file formats go, .epub and .pdf couldn’t be more different. While
.epub is essentially XML, the pdf spec is several hundred pages long and has to
cover things like graphics and even embedded JavaScript.
The following program shows three simple utility functions for reading data
from both formats and outputting to a text file.
Example Coding # 7: Utility Functions for PDF and EPUB
#ch4a.py
Notice that both scrape_pdf and scrape_epub output to a file using UTF-8
encoding. This is because eBooks may contain characters from a different
language or ones that can’t be represented using the default encoding scheme.
Generally, it is a good idea to go with UTF-8 if you are unsure what encoding an
eBook is using (you will receive an error if you get the encoding wrong).
The epub module needs some extra sanitization compared to PyPDF2. The
bleach module designed to remove dangerous code from HTML documents, but
it does a somewhat good job of also removing extra formatting from the raw
epub text. Next, a regular expression pattern is used to substitute any non-
alphanumeric characters with whitespace. If you find it desirable to parse the
XML, you may want to write the raw data instead of bleaching and then using
the regex substitute. However, if you are interested in just the text, this solution
might be a good fit.
Finally, the scrape_directory function can take an entire folder of ebooks in .pdf
or .epub format and extract the text using the previous two functions. It uses a
fun little utility that prints a progress bar to the console while you wat.
Documentation
Pypdf2: https://Pythonhosted.org/PyPDF2/
Ebup: https://pypi.org/project/epub/
Chapter 5: Rouge-Like Games in Console
Back in the days before computer graphics where a thing, bored programmers
designed text-based games that they could play from their terminals. Usually,
these games used an element of randomness to keep things interesting and were
heavily story oriented. Today any game that is played in the terminal is said to be
‘Rouge-like’ but the genre has extended itself to graphical games as well.
The board is a simple 2-d array backed structure that can be easily printed to the
console using a series of if statements. Since arrays are indexable player
movement can be dictated by changing the indices.
This little game is completely luck based and therefore probably not that fun, but
it is a nice example of how one might begin to program a rouge like using
Python. There are other more sophisticated libraries that allow you to work with
the command line, most notably the curses library for those using UNIX like
systems and Pygcurse for windows.
Extensions for Chapter 5
1. Add a turn counter that lets the player know for how many turns they
survived. Alternatively, use the counter to activate events later in the
game that progress the story.
2. Add your own set of messages. See if you can program a probability
distribution so that some events occur more than others do.
3. Add enemies or index specific events that move around the board
each turn
4. Add more levels, maybe some that aren’t randomly generated
5. Add Walls or blocked passageways
6. Add food or some other item that heals the player or maybe an
inventory system as well.
7. Add a flashlight or other light source that lets the player see more
than the tile they are on or have visited. Alternatively, implement fog
so that the player doesn’t see the path they have walked.
Chapter 6: Creating Games Using Pygame
The next logical step from writing command-line games is to use a graphics
library like Pygame to make things interesting. Pygame has several graphics
rendering capabilities including 3D support as well as a sound library.
Unfortunately, CPython is notoriously slower than other languages and
sometimes not well suited for intensive graphics processing. Even so great
games have been written using Pygame (even a few commercial ones) and you
will likely have a blast making games of your own, even if they are simple.
Pygame is easily installable using pip.
As mentioned in the previous chapter, any game needs to have a main loop. Each
Pygame program must also include a call to the event loop inside of the main
loop. Otherwise, it will freeze. There are a few other things that need to happen,
such as the initiation of the pygame module using pygame.init while not
required, it is considered good practice. This method will load pygame modules
for you. Next, set up your display with pygame.display.set_mode. It takes a
tuple or list containing screen dimensions for an argument. You should also
create a clock object using pg.time.Clock to set up a frame per second timer.
Also not needed, but will make your games easier to animate.
The rest of the program is a matter of calling the event loop, doing any
calculations, and drawing objects to the screen. For Simon Says only primitives
are needed. These are built-in shapes that the pygame engine can draw to the
screen using pygame.draw but you may use your own sprites as well. Make
sure to include a call to pygame.display.update or pygame.display.flip. These
methods actually update the screen on each game tick (execution of a loop).
Without these functions, the screen will not change. You can also call them
whenever you draw to the screen and want to see immediate results, rather than
wait for the entire loop to finish. Finally, for pygame to diplsay fluid animations,
the scene needs to be wiped every frame with a call to display.fill. If the entire
screen is being used by your program, this color can be black (0,0,0). Otherwise,
you might want to use a color that fits the background of your game.
Example Coding # 9: Simon Says
#ch9a.py
Simon Says is a simple game. It relies on an array that has a preloaded sequence
of colors to be displayed at each stage of play. The program above displays the
pattern to the user and then waits for input. Notice that you cannot stop the main
loop without making calls to time.sleep but this function should be avoided if
possible. Instead, use conditional checks that only run sometimes. The main
control in the program is the waiting_on_input variable. However, in practice
conditionals are rarely adequate for controlling the flow of a complex game.
Instead, there are techniques like using finite-state machines to keep track of the
state. Here it isn’t necessary. When the player fails to recall a pattern correctly is
a game over. Instead of shifting to the game over state, the game simply resets.
Example Coding # 10: Bubble Simulation
Pygame isn’t good for only programming games. Anything that uses graphics,
(think a screen saver) can also be modeled using it. This program is a simulation
of sorts that mimics a surge of bubbles underwater. Again, only pygame
primitives are used to draw to the screen.
The examples in this chapter use SQLite, an in-memory database that should
come already installed in Mac. If you use Windows, you can install the SQLite
interpreter from https://www. SQLite.org/download.html. Click on SQLite-
tools-win32-x86-3240000.zip. Extract the contents to some directory, preferably
the C:\ drive. To run it, simply navigate to that directory and type SQLite3. You
can mess around with things similar to how you might in a Python interpreter.
You don’t need to stay in that same directory for the examples. Feel free to
navigate back to the directory with your other Python examples for this book.
Example Coding # 12: The SQLite Connector
Instead of typing everything out in the interpreter, the following program can
execute SQL commands using pure Python. When you connect to an in-memory
database using the SQLite3 Python library a new database will be created if one
doesn’t exist in that name. The cursor object is the main interface into the
database.
The Tkinter module provides access to Tcl/Tk bindings that allow you to
program desktop windows. It is part of the standard library so there is no need to
install anything outright. The programs in this chapter show how to write Python
scripts that call the tcl bindings to display widgets. Beware that Tkinter
documentation is sometimes difficult to find. One source for Python
documentation can be found at http://effbot.org/tkinterbook/ and the official
Tcl/tk documentation is always available at
https://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm.
Tkinter programs follow the general pattern of instantiating a root window using
the tkinter.Tk class. Usually, this is passed to a class such as Window. All other
widgets are children of the root window in one way or another. The program
runs by calling mainloop on the Tk object.
Three geometry managers come with Tkinter. They are the pack, grid, and
place managers. We will only look at the former two as place is less useful. The
pack manager places widgets on the main window almost like an elastic band
that can be stretched to fit the screen. These widgets are placed in the middle of
the window and can be aligned to corners. The grid manager has you define a
grid with rows and columns and explicitly state what rows and columns a widget
should span.
Example Coding # 14: Console Logger
This program uses the grid manager to place widgets. A number of different widgets are introduced here;
they are the Frame, Label, Button, Entry and Text widgets. Notice that each widget takes a window as
first argument, usually the root window but sometimes a Frame. The grid manager is tricky to understand at
first, because the grid is defined as you add widgets and not before. If you try placing a widget on column
10 when there is nothing defined in that range, Tkinter will still place it where you expect column 0 to be.
The sticky argument lets you choose which side the widget can expand to fill the entire cell. The grid
manager takes into account the heights and widths of widgets, so be careful placing large ones as they will
morph the size of cells.
#ch8a.py
Button widgets have a command argument that allows you to pass a callback
function. The callback is executed when the button is pressed. Make sure that all
commands passed are just pointers to functions rather than function calls with
parentheses.
Normally the Text widget allows the user to type but in this example, it is
disabled using the configure method to set state to ‘disabled’. We don’t want the
user writing on it. Text widgets use an indexing system in the form of
“line.character”. Alternatively, indices can be reserved words, in this case, ‘end’
prints to the last character index. The END constant means the same thing.
Example Coding #15: Binary Calculator
This program uses the same Binary class from Chapter 2 so make sure to import
it. Instead of using the grid manager, this example shows how to use the pack
manager. You can use either one in your programs and it is mostly a matter of
preference. However, you can’t mix both or you will get an error.
Packed widgets can be moved to a side using the side argument given that there
is space. Notice that the Frame widget creates an empty widget or window that
other widgets can be placed on. The example uses empty frames to group Button
and Entry widgets. If you are wondering what StringVar is, they are objects that
correspond to text inside of other widgets. They are the only means to add data
to Entry widgets and later retrieve it.
#ch8b.py
Example Coding # 16: Mock Text Editor
This is a longer entry than the previous one but is still not a full program.
Creating a full-text editor is possible with Tkinter. In fact, the Python IDLE is
programmed using it. The following is more like a skeleton of a full text editor.
Two new widgets are introduced, the PanedWindow and TreeView from the ttk
module. PanedWindow widgets allow you to group widgets together and change
their size. TreeView widgets are used for listing items like files in a directory.
#ch8c.py
The TreeBox class serves as a tree structure of sorts, with each node
representing a file or folder similar to the first example in this book. However,
unlike the first example, TreeBox uses a recursive solution to finding parents in
the tree.
Extensions for Chapter 8
1. Tkinter supports styling of fonts. For Example # 14, add a drop down
menu type of widget that lists different levels of severity. For each
level style the text outputted to the console with a different color (i.e.
read for warning)
2. If you programmed support for multiplication and division on the
Binary code, add two buttons for both of them. Alternatively,
redesign the interface to also accept integers like a traditional
calculator app.
3. With a little work, the mock text editor can be extended to a full-
blown application. Some things you might consider adding: a menu
system for opening files, commands for saving your work, and font
styling.
Documentation
Tkinter: http://effbot.org/tkinterbook/
Tcl/TK: https://www.tcl.tk/
Chapter 9: Data Munging and Analysis with Pandas
For this chapter, you want to download the 2016 Fatality Analysis Reporting
System (FARS) data off the NHTSA FTP site ftp://ftp.nhtsa.dot.gov/fars/. Scroll
down to the year 2016 and download the FARS2016NationalCSV file. If you
extract the contents, you will see dozens of different files. Relax; this is what a
production dataset looks like. The examples in this chapter will only use the
accident.csv, vehicle.csv, person.csv, and parkwork.csv files so make sure you
extract at least those four.
Example Coding # 17 Merging Data
A common task in data science is to preprocess data, to put it a format that is
easy to analyze. This is called data munging. One form of data munging is to
merge data into a single collection.
We first define a list of variables that we are interested in and only load those
from the .csv files. Notice that some of these repeats, they are used for merging.
You can think of the FARS data as having three levels: accident -> vehicle ->
person. Each row in accident.csv corresponds to a single accident, each row in
vehicle.csv corresponds to a single vehicle in an accident, and each row in
person.csv corresponds to a single person. A large dataset like this comes with a
user manual that can be downloaded from ftp://ftp.nhtsa.dot.gov/fars/FARS-
DOC/Analytical%20User%20Guide/
#Ch9a.py
After merging the data, the result is a single pandas data frame per state. Note
that since the lowest level is the person.csv file, each row in the new data frames
refers to a person. The additional variables from the other files are added in. Due
to the awkward shape of the data, some missing values result from the merge,
which can promptly be dropped using the dropna method.
Example Coding # 18: Basic Statistics and Reporting
This program focuses more on analysis. We use the matplotlib module that you
can install via pip. Still using the same data from before, import the data frames
from the previous example.
You may be tempted to index data frames like regular lists, don’t. pandas data
frames have their own ways of indexing. For example, you can index by column
name to get the entire column or use .iloc to index by row number. You can get a
quick introduction to these and other methods by googling ‘Python pandas
cheatsheet’. If you print the fatals and drunks variables, you should see a
dictionary mapping for the number of fatal accidents and drunk driver involved
accidents per state.
#ch9b.py
To display graphs you can either call plt.show or save the plot to disk by using
plt.savefig. Refer to the user manual if you are unsure what variable values
mean. Many insights require some sort of visualization of data. For example, the
age distribution graph shows a disproportionate amount of fatalities belong to
young drivers (under 25) and the graph about travel speed shows that most
fatalities occur at moderate, rather than high speeds.
Chapter 10 Extensions
1. If you look over the user manual, you will notice there are hundreds
of different variables. See if any catch your eye and try to run your
own analyses.
2. The FARS dataset spans as far back as 1975. A real data munging
challenge would be consolidating several years of data into a single
file. The challenge lies in that certain variables change over years;
both their names and values are different (refer to the manual). A
little warning, you already know that the dataset has three main levels
(accident, vehicle, person) it may be less than ideal to merge these
into a single file. A better idea would be to merge them into three
separate files that span years. You will need a unique identifier for
each record. This can be achieved by combining year and st_case.
3. Add the entire FARS dataset (accident, vehicle, person) into an
SQLite database. If you do this, make sure you have at least 3GB of
free space lying around, as records will add up.
Documentation
Pandas: https://pandas.pydata.org/
FARS: https://www.nhtsa.gov/research-data/fatality-analysis-reporting-system-
fars
Chapter 10: Web Development in Flask
When people talk about web development using Python, they are referring to
backend systems rather than the visual aspects of websites. If you are new to
web development in general, you may consider taking a brief tour on google to
find out more about HTML, CSS, and JavaScript. This chapter focuses mainly
on website backends but will include some snippets of HTML code, so be
prepared for that.
For now, focus on the HTML string that is returned by the index function. The
resulting web page is what the flask program returns to the browser when a
connection is established. The @route decorator stems from the name of the
flask variable, in this case, @application.route. Also known as the routing
decorator, this is what tells flask what to send to the browser when the address ‘/’
is entered into the search bar.
Go ahead and open a browser and point it to 127.0.0.1:5000. You should see the
example web page (Note that the ‘/’ route is synonymous with 127.0.0.1:5000/)
The debug argument tells flask to run in debug mode and will automatically
reload the script when a change is detected to the file. No more having to type
out Python file.py!
#ch10a.py
All you need to know about templates is that they are .html files that Python can
preprocess. Flask uses a templating engine called jinja2 whose documentation
you can read at http://jinja.pocoo.org/docs/2.10/. Thankfully, the jinja2 syntax is
very similar to Python. If you look at templates/index.htnl below, anything that
is inside of curly braces count as jinja2 syntax. Jinja2 can access variables that
you pass to the render_template function. The previous examples mimicked
this functionality by using format strings. Hopefully, you will agree that
templates are far superior. Make sure your template file is located in the same
directory as your application script, or flask won’t be able to locate it. Also,
make sure it is named templates.
Again, there is a lot of HTML in this section. If something looks unfamiliar, feel
free to look it up.
templates/index.html
templates/login.html
templates/signup.html
If you still aren’t convinced about the power of templates, you will be after
reading the above code. Templates not only allow you to send information to the
HTML file, but they can also change the state of the webpage or application by
displaying information if and only if a user is logged in. Finally, the database
connection ensures that all data remains with persistence.
Extensions for Chapter 11
1. If you hadn’t noticed, the applications you wrote in flask are UGLY.
While programmers aren’t renowned for their design abilities, it is
worth brushing up on some basics. Look up HTML and CSS styling
to make your websites look prettier.
2. Using an HTML table for storing notes looks god-awful. See if you
can think of a better way to render these. Remember that all you need
to do is run a loop with jinja2 and process each note.
3. Feel free to add more content to the final website, either images,
additional text, menus—you name it.
Documentation
Flask: http://flask.pocoo.org/
Flask-sqlalchemy: http://flask-sqlalchemy.pocoo.org/2.3/
Sqlalchemy: https://www.sqlalchemy.org/
Conclusion
Thank you for making it through to the end of Python: 21 Sample Codes and
Advanced Crash Course Guide in Python Programming. Let’s hope it was
informative and able to provide you with all of the tools you need to achieve
your goals whatever they may be.
Where do you go from now? When picking up a book such as this, one thing is
clear: you know the basics and are hungry for learning how to improve your
coding skills. Part of this comes down to learning new libraries and techniques,
and another part comes down to honing your craft. The 21 examples in this book
are all extensible in their own right. Even if you follow the suggested extensions,
you can still think of novel ones on your own.
Don’t be scared to mess around with the code once you have it working. Break
things, build them up again, and break them some more. Truly understand
things. Go back and modify the examples, chances are you will find better ways
of doing the same things.
There are hundreds of books out there, and true to the open source spirit, there
are hundreds of large open source projects that you can look at. Many of the
libraries used in this book, for example, are all open source. Find code,
understand it, and improve on it.
Finally, if you found this book useful in any way, a review on Amazon is always
appreciated!