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
class Node: | |
def __init__(self,data): | |
self.data = data | |
self.next = None | |
class Solution: | |
def display(self,head): | |
current = head | |
while current: |
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
class Command: | |
def execute(self): | |
pass | |
class Copy(Command): | |
def execute(self): | |
print("Copying...") | |
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
# Python 3 has a built in feature that allows us to designate a certain method as an abstract method. | |
# When a method is decorated as an abstract method it should be overrriden by a subclass. | |
from abc import ABC, abstractmethod | |
class AbstractExpression(): | |
@abstractmethod | |
def interpret(self): | |
pass | |
class NonterminalExpression(AbstractExpression): |
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 pickle | |
class Originator: | |
def __init__(self): | |
self.__state = None | |
def create_memento(self): | |
return pickle.dumps(vars(self)) | |
def set_memento(slef, memento): | |
selfprevious_state = pickle.loads(memento) |
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
# compare each item in a list with the rest, only once? | |
for index, this in enumerate(mylist): | |
for that in mylist[index+1:]: | |
compare(this, that) | |
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
def arrayChange(inputArray): | |
count = 0 | |
adam = inputArray[0] | |
for el in inputArray[1:]: | |
if el <= adam: | |
count += adam-el+1 | |
adam +=1 | |
else: | |
adam = el | |
return coutn |
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
# not so Pythonic way | |
def palindromeRearranging(inputString): | |
letter_counts_dict = dict() | |
for letter in inputString: | |
if letter in letter_counts_dict: | |
letter_counts_dict[letter] += 1 | |
else: | |
letter_counts_dict[letter] = 1 | |
threshold = 0 | |
for k,v in letter_counts_dict.items(): |
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
class Config(object): | |
""" | |
Common configurations | |
""" | |
class DevelopmentConfig(Config): | |
""" | |
Development configurations | |
""" |
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 flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
if __name__ == '__main__': | |
app.debug = True | |
app.run() |
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
# instance/config.py | |
SECRET_KEY = 'b=3=!0^96*8jhkvkfbqf*1!yn-9' | |
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://USER:PASSWORD@localhost/db_name' |
OlderNewer