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 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: |
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
'''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']. |
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
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): |
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
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: |
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
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: |
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 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: |
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
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 = '' |
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 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'], |