<jupyter_start><jupyter_text>Import Networkx Package<jupyter_code>import networkx

my_graph = networkx.Graph()<jupyter_output><empty_output><jupyter_text>Add Nodes<jupyter_code>my_graph.add_node(1)
my_graph.add_node(2)
my_graph.add_node(3)
my_graph.add_node(4)<jupyter_output><empty_output><jupyter_text>Add Edges<jupyter_code>my_graph.add_edge(1,2)
my_graph.add_edge(3,1)
my_graph.add_edge(2,4)
my_graph.add_edge(1,4)<jupyter_output><empty_output><jupyter_text>Print Names of Nodes<jupyter_code>node_list = my_graph.nodes()
print(node_list)<jupyter_output>[1, 2, 3, 4]<jupyter_text>Print Edges in Graph<jupyter_code>edge_list = my_graph.edges()
print(edge_list)<jupyter_output>[(1, 2), (1, 3), (1, 4), (2, 4)]<jupyter_text>Remove nodes and edges<jupyter_code>my_graph.remove_edge(2,4)
edge_list = my_graph.edges()
print(edge_list)
my_graph.remove_node(2)
node_list = my_graph.nodes()
print(node_list)<jupyter_output>[(1, 2), (1, 3), (1, 4)]
[1, 3, 4]<jupyter_text>Degree and Neighbors<jupyter_code>## Total number of edges
edge_total = my_graph.number_of_edges()
print(edge_total)

## Degree
deg = my_graph.degree(1)
print(deg)

## Neighbors
neigh = my_graph.neighbors(1)<jupyter_output>4
3<jupyter_text>Count Triangles in Graph<jupyter_code>def countTriangles(g, isDirected):
    nodes = len(g)
    count_Triangle = 0
    
    
    for i in range(nodes):
        for j in range(nodes):
            for k in range(nodes):
                if( i!=j and i!=k and j!=k and g[i][j] and g[j][k] and g[k][i]):
                    count_Triangle += 1
    return count_Triangle/3 if isDirected else count_Triangle/6
graph = [[0,1,1,0],
        [1,0,1,1],
        [1,1,0,1],
        [0,1,1,0]]
x = countTriangles(graph, False)
print(x)<jupyter_output>2
{'fraction_non_alphanumeric': 0.1457257601835915, 'fraction_numerical': 0.03499713138267355, 'mean_word_length': 5.6311787072243344, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '396495', 'license': 'MIT', 'n_tokens_mistral': 771, 'n_tokens_neox': 740, 'n_words': 119, 'path': 'Package_Demos/NetworkX.ipynb', 'repo_name': 'glickmac/Misc_Scripts', 'size': '1743'}