Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# elapsed timer: as generator | |
# Youtube subscribe link: https://goo.gl/ZgZrZ5 | |
# Gerry Jenkins | |
import time | |
class ElapsedTime(): | |
def __init__(self): | |
# store only start time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hexgame.py: to learn the hex digits for binary patterns | |
# written to run in python 2.7 and 3+ | |
# Subscribe: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1 | |
from __future__ import division, print_function | |
from random import randrange | |
from time import time | |
import sys | |
hex_digits = '0123456789ABCDEF' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gen sequence i.e. "1,3,5-7,9" > [1,3,5,6,7,9] | |
def seq_gen(s): | |
for item in s.split(','): | |
if '-' in item: | |
a, b = map(int, item.split('-')) | |
for i in range(a,b+1): | |
yield i | |
else: | |
if len(item): | |
yield int(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' comparing speed of new dataclass | |
with standard class attributes and slots, | |
running in 3.7.0b1''' | |
# subscribe to me: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1 | |
# I recommend reading PEP557: https://www.python.org/dev/peps/pep-0557/ | |
# this code at gist: http://bit.ly/slotsVdatclass | |
from dataclasses import dataclass | |
from timeit import timeit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" One Example of how to implement a Adjacency Matrix implementation of a Graph Data Structure | |
that matches the Abstract Data Type as defined in the eBook | |
https://runestone.academy/runestone/static/pythonds/index.html | |
and goes with the video course at http://youtube.com/gjenkinslbcc channel | |
""" | |
class Vertex(object): | |
"""vertex with key and optional data payload""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Graph Data Structure: Adjacency List implementation | |
that matches the Abstract Data Type as defined in the eBook | |
https://runestone.academy/runestone/static/pythonds/index.html | |
and goes with the video course at http://youtube.com/gjenkinslbcc channel | |
This code is attributed to the book | |
"Problem Solving with Algorithms and Data Structures using Python" | |
by the Authors Bradley N. Miller and David Ranum | |
under the Creative Commons | |
Attribution-NonCommercial-ShareAlike 4.0 International License (CC-BY-NC-SA) | |
License link: https://goo.gl/m2m1ww |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Undirected Graph ADT with edge data stored as adj_vertices dict for each Vertex | |
# The key to each edge is a nomalized tuple of the vertex ids ordered from low to high | |
# edge id (eid) for v1, v2 is (v1,v2) or (v2,v1) such that the first tuple item is less than second | |
def edge_id(v1,v2): # normalize key v1,v2 to tuple (v_low,v_hi) | |
return (v1, v2) if v1 <= v2 else (v2, v1) | |
class Vertex(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import re | |
import requests | |
import csv | |
import time | |
import json | |
# version 1.1 added handling of youtube.com/channel/ | |
# to already handling of youtube.com/user based channels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
""" Create random events where event probabilities are | |
set by a frequency list | |
This shows two functional approaches, the second being more terse | |
and then a object oriented approach""" | |
# functional approach using a closure | |
# setup: x = event_gen(freq_table) | |
# get sample: x() -> sample index | |
def event_gen(freq_table): |
OlderNewer