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.5||stdio.py||functions to read/write numbers and text from/to stdin and stdout|
|1.5||stddraw.py||functions to draw geometric shapes|
|1.5||stdaudio.py||functions to create, play, and manipulate sound|
|2.2||stdrandom.py||functions related to random numbers|
|2.2||stdarray.py||functions to create, read, and write 1D and 2D arrays|
|2.2||stdstats.py||functions to compute and plot statistics|
|3.1||color.py||data type for colors|
|3.1||picture.py||data type to process digital images|
|3.1||instream.py||data type to read numbers and text from files and URLs|
|3.1||outstream.py||data 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 stdlib-python.zip.
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 introcs-python.zip and the data as introcs-data.zip.
|1||ELEMENTS OF PROGRAMMING||DATA|
|1.1.2||useargument.py||using a command-line argument||–|
|1.2.1||ruler.py||string concatenation example||–|
|1.3.1||flip.py||flipping a fair coin||–|
|1.3.2||tenhellos.py||your first loop||–|
|1.3.3||powersoftwo.py||computing powers of two||–|
|1.3.4||divisorpattern.py||your first nested loops||–|
|1.3.7||binary.py||converting to binary||–|
|1.3.8||gambler.py||gambler's ruin simulation||–|
|1.4.1||sample.py||sampling without replacement||–|
|1.4.2||couponcollector.py||coupon collector simulation||–|
|1.4.3||primesieve.py||sieve of Eratosthenes||–|
|1.4.4||selfavoid.py||self-avoiding random walks||–|
|1.5.1||randomseq.py||generating a random sequence||–|
|1.5.2||twentyquestions.py||interactive user input||–|
|1.5.3||average.py||averaging a stream of numbers||–|
|1.5.4||rangefilter.py||a simple filter||–|
|1.5.5||plotfilter.py||standard input to draw filter||usa.txt|
|1.5.7||playthattune.py||digital signal processing|
|1.6.1||transition.py||computing the transition matrix|
|1.6.2||randomsurfer.py||simulating a random surfer||–|
|1.6.3||markov.py||mixing a Markov chain||–|
|2.1.1||harmonicf.py||harmonic numbers (revisited)||–|
|2.1.3||coupon.py||coupon collector (revisited)||–|
|2.1.4||playthattunedeluxe.py||play that tune (revisited)|
|2.2.1||gaussian.py||Gaussian functions module||–|
|2.2.2||gaussiantable.py||sample Gaussian client||–|
|2.2.4||ifs.py||iterated function systems|
|2.3.2||towersofhanoi.py||towers of Hanoi||–|
|2.4.1||percolationv.py||vertical percolation detection|
|2.4.2||percolationio.py||percolation support functions||–|
|2.4.3||visualizev.py||vertical percolation visualization client||–|
|2.4.4||estimatev.py||vertical percolation probability estimate||–|
|2.4.6||visualize.py||percolation visualization client||–|
|2.4.7||estimate.py||percolation probability estimate||–|
|3||OBJECT ORIENTED PROGRAMMING||DATA|
|3.1.1||potentialgene.py||potential gene identification||–|
|3.1.2||chargeclient.py||charged particle client||–|
|3.1.5||grayscale.py||converting color to grayscale|
|3.1.8||potential.py||visualizing electric potential||charges.txt|
|3.1.10||stockquote.py||screen scraping for stock quotes||–|
|3.1.11||split.py||splitting a file||djia.csv|
|3.2.1||charge.py||charged-particle data type||–|
|3.2.2||stopwatch.py||stopwatch data type||–|
|3.2.3||histogram.py||histogram data type||–|
|3.2.4||turtle.py||turtle graphics data type||–|
|3.2.9||complex.py||complex number data type||–|
|3.2.11||stockaccount.py||stock account data type||turing.txt|
|3.3.1||complexpolar.py||complex numbers (revisited)||–|
|3.3.2||counter.py||counter data type||–|
|3.3.3||vector.py||spatial vector data type||–|
|3.3.4||sketch.py||sketch data type||genome20.txt|
|3.4.1||body.py||gravitational body data type||–|
|4.1.2||doublingtest.py||validating a doubling hypothesis||–|
|4.1.3||timeops.py||timing operators and functions||–|
|4.1.4||bigarray.py||discovering memory capacity||–|
|4.2.1||questions.py||binary search (20 questions)||–|
|4.2.2||bisection.py||binary search (inverting a function)||–|
|4.2.3||binarysearch.py||binary search (sorted array)|
|4.2.5||timesort.py||doubling test for sorting functions||–|
|4.3.1||arraystack.py||stack (resizing array implementation)||tobe.txt|
|4.3.2||linkedstack.py||stack (linked list implementation)||tobe.txt|
|4.3.4||linkedqueue.py||queue (linked list implementation)||tobe.txt|
|4.3.5||mm1queue.py||M/M/1 queue simulation||–|
|4.3.6||loadbalance.py||load balancing simulation||–|
|4.4.3||hashst.py||hash symbol table data type||–|
|4.4.4||bst.py||BST symbol table data type||–|
|4.5.1||graph.py||graph data type||tinygraph.txt|
|4.5.2||invert.py||using a graph to invert an index|
Snap.py 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.
Snap.py provides performance benefits of SNAP, combined with flexibility of Python. Most of the SNAP functionality is available via Snap.py in Python.
The latest version of Snap.py 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 Snap.py 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 Snap.py based programs should continue to work.
Snap.py supports Python 2.x and Python 3.x on macOS, Linux, and Windows 64-bit. Snap.py 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.
Snap.py 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 Snap.py, if you want to use plotting and visualizations in Snap.py:
- Gnuplot for plotting structural properties of networks (e.g., degree distribution);
- Graphviz for drawing and visualizing small graphs.
Snap.py can be installed via the pip module. To install Snap.py, 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 Snap.py for. You might also need to add --user after install, if pip complains about your adminsitrative rights. The most recent notes about installing Snap.py on various systems is available at this document: Snap.py Installation Matrix.
Manual Install of Snap.pyIf you want to use Snap.py in a local directory without installing it, then download the corresponding Snap.py package for your system, unpack it, and copy files snap.py and _snap.so (or _snap.pyd) to your working directory. The working directory must be different than the install directory.
Documentation and Support
Snap.py Tutorial and Manual are available.
Snap.py 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 Snap.py specific component was given at the WWW2015 conference in Florence.
Use the SNAP and Snap.py users mailing list for any questions or a discussion about Snap.py installation, use, and development. To post to the group, send your message to snap-discuss at googlegroups dot com.
Quick Introduction to Snap.py
This document gives a quick introduction to a range of Snap.py operations.
Several programs are available to demonstrate the use of Snap.py. The programs are also useful as tests to confirm that your installation of Snap.py is working correctly:
- quick_test.py: a quick test to confirm that Snap.py works on your computer;
- intro.py: combines the code that is shown below on this page;
- tutorial.py: contains the code from Snap.py tutorial;
- tneanet.py: demonstrates the use of the TNEANet network class;
- cncom.py: demonstrates the use of functions for connected components;
- attributes.py: demonstrates the use of attributes in TNEANet network class;
- test-gnuplot.py: a quick test to confirm that gnuplot works;
- test-graphviz.py: a quick test to confirm that Graphviz works.
The code from intro.py is explained in more details below.
All the code assumes that Snap.py 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
Snap.py 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:
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 Snap.py 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 Snap.py 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, Snap.py 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 more details on Snap.py functionality, check out the Snap.py Manuals.
Computing Structural Properties of Networks
SNAP provides rich functionality to efficiently compute structural properties of networks. Most functions support all graph/network types.
For more details on Snap.py functionality, check out the Snap.py Manuals.