Skip to content

Instantly share code, notes, and snippets.

View loisgh's full-sized avatar

Lois loisgh

View GitHub Profile
class FirstClass():
myclass_variable = "Here is some data"
def method_one(self):
print("You are in FirstClass method_one")
def method_two(self):
print("You are in FirstClass method_two")
print("My Class Variable: {}".format(FirstClass.myclass_variable))
0
@loisgh
loisgh / test1.py
Created October 2, 2018 21:37
My Test Gist
def main():
print("test1")
main()
class Node:
# Constructor to initialize the node object
def __init__(self, data, neighbors=[]):
self.data = data
self.neighbors = []
class Graph:
def __init__(self):
self.head = None
class Node:
# Constructor to initialize the node object
def __init__(self, data, neighbors=[]):
self.data = data
self.neighbors = []
class Graph:
def __init__(self):
self.head = None
def find_1d_peak(arr, low, high, n):
mid = low + (high - low) / 2
if ((mid == 0 or arr[mid - 1] <= arr[mid]) and
(mid == n - 1 or arr[mid + 1] <= arr[mid])):
return mid
elif (mid > 0 and arr[mid - 1] > arr[mid]):
return find_1d_peak(arr, low, (mid - 1), n)
else:
return find_1d_peak(arr, (mid + 1), high, n)
def find_1d_peak(the_list, first, last):
if first == last:
return first
if last == first + 1 and the_list[first] >= the_list[last]:
return first
if last == first + 1 and the_list[first] < the_list[last]:
return last
import Queue
def matching_parens(in_list):
paren_q = Queue.Queue()
for item in in_list:
if item in ('(','['):
paren_q.put(item)
elif item == ')':
check = paren_q.get()
if check == '(':
def binary_search(target_array, target, first, last):
#If the array is empty return -1
if not len(target_array):
return -1
#if the array has only one element in it, check that element.
elif len(target_array) == 1:
if target_array[0] == target:
return 0
else:
#The output is as follows:
# word followed by "total: " with the total amount next to it
# 2:1 The sentence that the word appears in and the number of times it appears.
# 2:1 means that the word appears in the second sentence one time.
class Concordance
shash = Array.new
total_hash = Hash.new