Skip to main content

A simple graph package

Project description

Introduction

The simple-graph module contains basic functions for graph.

Concept

A graph is a structure to hold a set of objects in which some pairs of the objects are connected.

A graph contains two components: vertices and edges.

We consider both directed and undirected edges in this project. If the edges are undirected, the graph is called undirected graph, on the other hand, it is called directed graph.

License

simple-graph is a free software. See the file LICENSE for the full text.

Install

pip install simple-graph

or update

pip install --upgrade simple-graph

Usage

Basic operations

from simple_graph import Graph
G = Graph()
G.add_edge(1, 2)
print(G.has_edge(1, 2))

ouput:

True
G = Graph({0: [1, 2], 1: [2]})
print(G.neighbors(0))

output:

[1, 2]

Statistics

G = Graph({ 
    "a" : ["c"],
    "b" : ["c","e","f"],
    "c" : ["a","b","d","e"],
    "d" : ["c"],
    "e" : ["b","c","f"],
    "f" : ["b","e"]
})

print(G.find_path('a', 'b'))
print(G.diameter())

output:

['a', 'c', 'b']
3

Check Wiki for more details.

Authors

qrcode_for_wechat_official_account

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_graph-0.1.9.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

simple_graph-0.1.9-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page