Skip to content

Instantly share code, notes, and snippets.

View iMel408's full-sized avatar
🎯
Focusing

Melissa iMel408

🎯
Focusing
View GitHub Profile
@iMel408
iMel408 / buy_low_sell_high.py
Last active June 2, 2019 11:41
Figure out the optimal buy and sell point for a given stock, given its prices yesterday. No "shorting"—you need to buy before you can sell.
def buy_low_sell_high(lst):
"""Figure out the optimal buy and sell point for a given stock, given its prices yesterday.
No "shorting"—you need to buy before you can sell. """
min_buy = lst[0]
mx_gain = 0
for i in range(len(lst)):
if lst[i] - min_buy >= mx_gain:
'''Fun with Anagrams:
QUESTION DESCRIPTION
Two strings are anagrams if they are permutations of each other. For example, "aaagmnrs" is an anagram of "anagrams".
Given an array of strings, remove each string that is an anagram of an earlier string, then return the remaining array
in sorted order.
For example, given the strings s = ['code', 'doce', 'ecod', 'framer', 'frame'], the strings 'doce' and 'ecod' are both
anagrams of 'code' so they are removed from the list. The words 'frame' and 'framer' are not anagrams due to the extra
'r' in 'framer', so they remain. The final list of strings in alphabetical order is ['code', 'frame', 'framer'].
samp_list = ['m','e','l']
def list_perm(prefix,suffix):
suffix_size = len(suffix)
if suffix_size == 0:
print(prefix)
else:
for i in range(0,suffix_size):
@iMel408
iMel408 / binary_search_algorithm.py
Created March 24, 2019 19:26
find position of a given int in an ordered list
ex_list = [0,1,2,3,4,5,6,7,8,9,10]
def binary_search(lst, num):
""" find position of a given int in an ordered list """
beg = 0
end = len(lst) - 1
while beg <= end:
@iMel408
iMel408 / multi_linear_search.py
Created March 24, 2019 19:12
multi linear search using enumerate method.
ex_list = [0,1,0,2,3,4,5,6,0,8,9,10]
def linear_search_multi(list, element):
""" find all index positions of a given element within a list"""
positions = []
for i, v in enumerate(list):
if list[i] == element:
@iMel408
iMel408 / calculate_factorial.py
Created March 24, 2019 18:52
calculate factorial of a given pos int. #practice
def calc_factorial(n):
""" calculate factorial of a given positive int"""
x = 1
if n < 0:
return 'error: param was neg int'
elif n == 1:
return(1)
else:
@iMel408
iMel408 / basic_string_encryption.py
Created March 24, 2019 18:16
basic string encryption using ord() and char() methods. based on excercise snippet found on @coderpedia ig.
text = 'meet me at the nut house'
def encrypt_str(txt):
"""
basic string encryption using:
ord() returns int representing Unicode for given char.
char() returns str representation in Unicode for given int.
"""
encrypted_txt = ''
@iMel408
iMel408 / helloworld.py
Created April 7, 2018 05:45
helloworld.py
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
trace_high = go.Scatter(
x=df.Date,
y=df['AAPL.High'],