Skip to content

Instantly share code, notes, and snippets.

View RobertTalbert's full-sized avatar

Robert Talbert RobertTalbert

View GitHub Profile
def flatten_list(lst):
flattened = []
for item in lst:
if isinstance(item, list):
flattened.extend(flatten_list(item))
else:
flattened.append(item)
return flattened
[3, 13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293,
313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683,
733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123,
1153, 1163, 1193, 1223, 1283, 1303, 1373, 1423, 1433, 1453, 1483, 1493, 1523,
1553, 1583, 1613, 1663, 1733, 1783, 1823, 1823, 1873, 1913, 1933, 1973, 1993,
2003, 2053, 2083, 2113, 2143, 2153, 2203, 2213, 2273, 2293, 2333, 2383, 2393,
2423, 2473, 2503, 2543, 2593, 2633, 2663, 2683, 2693, 2713, 2753, 2803, 2833,
2843, 2903, 2953, 2963]
# Load libraries
import networkx as nx
import matplotlib.pyplot as plt
# Generate the graph
## The second parameter is a probability that two distinct vertices are adjacent
## Raise the probability for more connections
g = nx.gnp_random_graph(8, 0.5)
# List of trails in North Ottawa Dunes park given as tuples.
# Vertex 100 = Trailhead in Coast Guard Park
# Vertex 200 = Trailhead at North Beach Park
# Vertex 300 = Trail endpoint at Hoffmaster State Park
[(100,1,.30), (1,24,.16), (1,2,.20), (2,19,.11), (19,25,.07),
(19,20,.16), (20,200, .16), (2,3,.49), (3,23,.11), (3,4,.34),
(4,23,.34), (4,18,.07), (4,21,.22), (5,21,.09), (5,6,.16),
(5,15,.23), (6,7,.34), (6,16,.07), (7,12,.12), (7,8,.15), (8,9,.21),
(8,13,.25), (9,10,.06), (10,11,.21), (10,12,.51), (11,300,.12),
# Generate a random tree
random_tree = nx.random_tree(n)
# Draw the tree
nx.draw(random_tree, with_labels=True, node_color="lightblue", font_weight="bold")
plt.show()
# Python code for MTH 325 F24 Homework 5
## 1. Iterating through a list
vertex_list = [(2,3), (2,4), (4,5), (1,3)]
for vertex in vertex_list:
print(vertex[1])
## 2. A dictionary
# Libraries
library(dplyr)
library(tidyverse)
library(ggplot2)
# Load data
colnames <- c("time", "email", "name", "section",
"challenge", "support",
"competence", "autonomy", "relatedness",
aliases

(insert tags here)

Definition

[!tldr] Definition Contents

# Use basic logic commands to "fake" set operations.
# Here's union:
U = [1,2,3,4,5,6,7,8,9,10]
A = [1,2,3,4,5,6]
B = [2,4,6]
# A union B
[x for x in U if ((x in A) or (x in B))]