Booksite Modules

Python is an interpretive language and so you need the interpretor to run your file, much like you need java runtime to run a jar file. Python Developer. £65,000 - £83,000. If you are looking for a new opportunity as a Python developer, this is the role for you!

Below is a table of the booksite modules that we use throughout the textbook and booksite and beyond.

1.5stdio.pyfunctions to read/write numbers and text from/to stdin and stdout
1.5stddraw.pyfunctions to draw geometric shapes
1.5stdaudio.pyfunctions to create, play, and manipulate sound
2.2stdrandom.pyfunctions related to random numbers
2.2stdarray.pyfunctions to create, read, and write 1D and 2D arrays
2.2stdstats.pyfunctions to compute and plot statistics
3.1color.pydata type for colors
3.1picture.pydata type to process digital images
3.1instream.pydata type to read numbers and text from files and URLs
3.1outstream.pydata type to write numbers and text to files

If you followed the instructions provided in this booksite (for Windows, Mac OS X, or Linux), then the booksite modules are installed on your computer. If you want to see the source code for the booksite modules, then click on the links in the above table, or download and unzip

Programs and Data Sets in the Textbook

Below is a table of the Python programs and data sets used in the textbook. Click on the program name to access the Python code; click on the data set name to access the data set; read the textbook for a full discussion. You can download all of the programs as and the data as

1.1.1helloworld.pyHello, World
1.1.2useargument.pyusing a command-line argument
1.2.1ruler.pystring concatenation example
1.2.2intops.pyinteger operators
1.2.3floatops.pyfloat operators
1.2.4quadratic.pyquadratic formula
1.2.5leapyear.pyleap year
1.3.1flip.pyflipping a fair coin
1.3.2tenhellos.pyyour first loop
1.3.3powersoftwo.pycomputing powers of two
1.3.4divisorpattern.pyyour first nested loops
1.3.5harmonic.pyharmonic numbers
1.3.6sqrt.pyNewton's method
1.3.7binary.pyconverting to binary
1.3.8gambler.pygambler's ruin simulation
1.3.9factors.pyfactoring integers
1.4.1sample.pysampling without replacement
1.4.2couponcollector.pycoupon collector simulation
1.4.3primesieve.pysieve of Eratosthenes
1.4.4selfavoid.pyself-avoiding random walks
1.5.1randomseq.pygenerating a random sequence
1.5.2twentyquestions.pyinteractive user input
1.5.3average.pyaveraging a stream of numbers
1.5.4rangefilter.pya simple filter
1.5.5plotfilter.pystandard input to draw filterusa.txt
1.5.6bouncingball.pybouncing ball
1.5.7playthattune.pydigital signal processing
1.6.1transition.pycomputing the transition matrix
1.6.2randomsurfer.pysimulating a random surfer
1.6.3markov.pymixing a Markov chain
2.1.1harmonicf.pyharmonic numbers (revisited)
2.1.2gauss.pyGaussian functions
2.1.3coupon.pycoupon collector (revisited)
2.1.4playthattunedeluxe.pyplay that tune (revisited)
2.2.1gaussian.pyGaussian functions module
2.2.2gaussiantable.pysample Gaussian client
2.2.3sierpinski.pySierpinski triangle
2.2.4ifs.pyiterated function systems
2.2.5bernoulli.pyBernoulli trials
2.3.1euclid.pyEuclid's algorithm
2.3.2towersofhanoi.pytowers of Hanoi
2.3.3beckett.pyGray code
2.3.4htree.pyrecursive graphics
2.3.5brownian.pyBrownian bridge
2.4.1percolationv.pyvertical percolation detection
2.4.2percolationio.pypercolation support functions
2.4.3visualizev.pyvertical percolation visualization client
2.4.4estimatev.pyvertical percolation probability estimate
2.4.5percolation.pypercolation detection
2.4.6visualize.pypercolation visualization client
2.4.7estimate.pypercolation probability estimate
3.1.1potentialgene.pypotential gene identification
3.1.2chargeclient.pycharged particle client
3.1.3alberssquares.pyAlbers squares
3.1.4luminance.pyluminance library
3.1.5grayscale.pyconverting color to grayscale
3.1.6scale.pyimage scaling
3.1.7fade.pyfade effect
3.1.8potential.pyvisualizing electric potentialcharges.txt
3.1.9cat.pyconcatenating files
3.1.10stockquote.pyscreen scraping for stock quotes
3.1.11split.pysplitting a filedjia.csv
3.2.1charge.pycharged-particle data type
3.2.2stopwatch.pystopwatch data type
3.2.3histogram.pyhistogram data type
3.2.4turtle.pyturtle graphics data type
3.2.5koch.pyKoch curve
3.2.6spiral.pyspira mirabilis
3.2.7drunk.pydrunken turtle
3.2.8drunks.pydrunken turtles
3.2.9complex.pycomplex number data type
3.2.10mandelbrot.pyMandelbrot set
3.2.11stockaccount.pystock account data typeturing.txt
3.3.1complexpolar.pycomplex numbers (revisited)
3.3.2counter.pycounter data type
3.3.3vector.pyspatial vector data type
3.3.4sketch.pysketch data typegenome20.txt
3.3.5comparedocuments.pysimilarity detection
3.4.1body.pygravitational body data type
3.4.2universe.pyn-body simulation
4.1.1threesum.py3-sum problem
4.1.2doublingtest.pyvalidating a doubling hypothesis
4.1.3timeops.pytiming operators and functions
4.1.4bigarray.pydiscovering memory capacity
4.2.1questions.pybinary search (20 questions)
4.2.2bisection.pybinary search (inverting a function)
4.2.3binarysearch.pybinary search (sorted array)
4.2.4insertion.pyinsertion sort
4.2.5timesort.pydoubling test for sorting functions
4.2.7frequencycount.pyfrequency counts
4.3.1arraystack.pystack (resizing array implementation)tobe.txt
4.3.2linkedstack.pystack (linked list implementation)tobe.txt
4.3.3evaluate.pyexpression evaluation
4.3.4linkedqueue.pyqueue (linked list implementation)tobe.txt
4.3.5mm1queue.pyM/M/1 queue simulation
4.3.6loadbalance.pyload balancing simulation
4.4.1lookup.pydictionary lookup
4.4.3hashst.pyhash symbol table data type
4.4.4bst.pyBST symbol table data type
4.5.1graph.pygraph data typetinygraph.txt
4.5.2invert.pyusing a graph to invert an index
4.5.3separation.pyshortest-paths client
4.5.4pathfinder.pyshortest-paths client
4.5.5smallworld.pysmall-world testtinygraph.txt
4.5.6performer.pyperformer-performer graph

About is a Python interface for SNAP. SNAP is a general purpose, high performance system for analysis and manipulation of large networks. SNAP is written in C++ and optimized for maximum performance and compact graph representation. It easily scales to massive networks with hundreds of millions of nodes, and billions of edges. provides performance benefits of SNAP, combined with flexibility of Python. Most of the SNAP functionality is available via in Python.

The latest version of is 6.0 (Dec 28, 2020), available for macOS, Linux, and Windows 64-bit. This version is a major release with a large number of new features, most notably a significantly improved way to call functions in Python, a NetworkX compatibility layer, standard Python functions to handle SNAP vector and hash types, new functions for egonets and graph union, and a completely revised package building infrastructure with a better support for various versions of Python (see Release Notes for details). These enhancements are backward compatible, so existing based programs should continue to work.

System Requirements supports Python 2.x and Python 3.x on macOS, Linux, and Windows 64-bit. requires that Python is installed on your machine. Make sure that your operating system is 64-bit and that your Python is a 64-bit version. is self-contained, it does not require any additional packages for its basic functionality. However, it requires external packages to support plotting and visualization functionality. The following packages need to be installed in addition to, if you want to use plotting and visualizations in

  • Gnuplot for plotting structural properties of networks (e.g., degree distribution);
  • Graphviz for drawing and visualizing small graphs.
Set the system PATH variable, so that Gnuplot and Graphviz are available, or put their executables in the working directory.

Installing can be installed via the pip module. To install, execute pip from the command line as follows:

If you have more than one version of Python installed on the system, make sure that python refers to the executable that you want to install for. You might also need to add --user after install, if pip complains about your adminsitrative rights. The most recent notes about installing on various systems is available at this document: Installation Matrix.

Manual Install of

If you want to use in a local directory without installing it, then download the corresponding package for your system, unpack it, and copy files and (or _snap.pyd) to your working directory. The working directory must be different than the install directory.

Documentation and Support Tutorial and Manual are available. is a Python interface for SNAP, which is written in C++. Most of the SNAP functionality is supported.For more details on SNAP C++, check out SNAP C++ documentation.

A tutorial on Large Scale Network Analytics with SNAP with a significant specific component was given at the WWW2015 conference in Florence.

Use the SNAP and users mailing list for any questions or a discussion about installation, use, and development. To post to the group, send your message to snap-discuss at googlegroups dot com.

Quick Introduction to

This document gives a quick introduction to a range of operations.


Several programs are available to demonstrate the use of The programs are also useful as tests to confirm that your installation of is working correctly:

  • a quick test to confirm that works on your computer;
  • combines the code that is shown below on this page;
  • contains the code from tutorial;
  • demonstrates the use of the TNEANet network class;
  • demonstrates the use of functions for connected components;
  • demonstrates the use of attributes in TNEANet network class;
  • a quick test to confirm that gnuplot works;
  • a quick test to confirm that Graphviz works.

The code from is explained in more details below.

All the code assumes that has been imported by the Python program. Make sure that you execute this line in Python before running any of the code below:

Graph and Network Types supports graphs and networks. Graphs describe topologies. That is nodes with unique integer ids and directed/undirected/multiple edges between the nodes of the graph. Networks are graphs with data on nodes and/or edges of the network. Data types that reside on nodes and edges are simply passed as template parameters which provides a very fast and convenient way to implement various kinds of networks with rich data on nodes and edges.

Graph types in SNAP:

Network types in SNAP:

Graph Creation

Example of how to create and use a directed graph:

Nodes have explicit (and arbitrary) node ids. There is no restriction for node ids to be contiguous integers starting at 0. In TUNGraph and TNGraph edges have no explicit ids -- edges are identified by a pair node ids.

Networks are created in the same way as graphs.


Many SNAP operations are based on node and edge iterators which allow for efficient implementation of algorithms that work on networks regardless of their type (directed, undirected, graphs, networks) and specific implementation.

Some examples of iterator usage in are shown below:

In general node iterators provide the following functionality:

For additional information on node and edge iterators, check out the Graph and Network Classes section in the reference manual.


With SNAP it is easy to save and load networks in various formats. Internally SNAP saves networks in compact binary format but functions for loading and saving networks in various other text and XML formats are also available.

For example, code for saving and loading graphs looks as follows:

Manipulating Graphs and Networks


SNAP provides rich functionality to efficiently manipulate graphs and networks. Most functions support all graph/network types.

For example:

For more details on functionality, check out the Manuals.

Computing Structural Properties of Networks

SNAP provides rich functionality to efficiently compute structural properties of networks. Most functions support all graph/network types.

Python Exe

For example:

For more details on functionality, check out the Manuals.

Pypl Stock