Commit 1627b6fc authored by Ian Stump's avatar Ian Stump

Merge branch 'week2day5' into 'master'


See merge request !2
parents 7ed8b992 5464e298
<!DOCTYPE html> <!-- just to say we want to use html site -->
<html lang="en">
<!-- defines main language of website -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- width device width is to make usre that it adapts to mobile/different screen sizes -->
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- to link the CSS file - we use link tag in the head -->
<title>Document</title> <!-- tittle of tab -->
<!-- head is for server and crawlers ; has meta data, SEO etc -->
<!-- search engines do not understand semantics so we need to use good practices, so that things are read as , e.g. if they see a button class (CSS) crawlers from search engines and disbaled user tools (screen readers) will know that is a "button", if button is made with div they will not know -->
<!-- div - main use for the is to split things; one interview question was to write a button, so thye see if you use a class (which you should) -->
<!-- p - is paragraph -->
<!-- span - different than div, bc it tkaes only the space it needs, can also be used to apply styles to specific words in a text -->
<!-- CSS RESET - copy paste it to my website to reset any browser specific styles -->
<!-- shoudl only have 2 types of clickable elements in website: anchor link (rediects to new page); and button -->
<!-- aside tag to put nav menus on the side of the page -->
<!-- hr - thematic break-->
<!-- form tag to submit information always need to wrap i tin this tag -->
<!-- google chrome - got to inspect element -- AUDIT -- gives us pointers to improve website -->
<!--CSS -->
<!--to add style we can add in a file in CSS, in a style tag in the html file (in the head), in the tags themselves; but best practice is to use CSS -->
<!-- in CSS order maters within each type (ID, class, tag), but there is a priority order between different categories: ID first, class second, tag third-->
<!-- display: inline, block and inline block - inline block allows to define margin and if we are applying it to a span tag, so we cna change the width and height a little -->
<!-- flex display is REALLY IMPORTANT-->
<!-- positions: STATIC(default), FIXED (relative to the viewport of the browser - ie always y=0, x=10px to the left), ABSOLUTE - relative to the body always, independent of parents - RELATIVE, changes it relative to the body OR the parent tag if the parent is not static (ie, has a class / a margin)-->
<!-- the best position is relative; for absolute or fixed elements, sometimes mobiles do not show them right while scrolling, bc these are outside the flow of a website-->
<!-- FLEX-->
<!-- FLEX, display flex , will add a flex direction automatically to row (not visible) - we can overwrite this with "flex-direction:column"-->
<!-- div tag always takes the width of the page, but height only as specified-->
<!-- screen readers will ALWAYS read semantics from html orders; if we change positions just using style, e.g. flex-direction", screen readers will not see that visual change but stick to what is in the html-->
<!-- justify content -- moves in the X axis; align items -- moves on the Y axis; they apply to all flex class paren, children-->
<!-- order and align self ( flex end) - child flex properties -->
<!-- to apply styles based on size of the screen-->
<!-- BEM-->
<!--interview question: if we know some CSS framework. answer: BEM-->
<!-- display: grid ;; allows to tell the elements hw to use the space, by defining how many ros and columns; it is an alternative to flex, better than flex for layouts-->
\ No newline at end of file
def count_repetition(array):
result = {}
for writer in array:
if writer in result:
result[writer] += 1
result[writer] = 1
return result
#WIP with nested loops
#method 1
def count_repetition(array):
result = {}
for x in range(len(array)):
for y in range(x + 1, len(array)):
# print(array[x], array[y]) #--the loop is working
if array[x] == array[y]:
print(array[x], array[y]) # it is getting the right amount of pairs
count +=1 # the COUNT is not right...
result[array[x]]= count
result[array[x]] = 1
return result
#method 2
def count_repetition(array):
result = {}
for x in array:
for y in array[1::]:
# print(x, y) #--the loop is working
count = 1
if x == y :
print(x, y)
count += 1 # the COUNT is not right...
result[x] = count
result[x] = count
return result
names = ['kerouac', 'fante', 'fante', 'buk', 'hemingway', 'hornby', 'kerouac', 'buk', 'fante']
# {'kerouac': 2, 'fante': 3, 'buk': 2, 'hemingway': 1, 'hornby': 1}
def exp_recursive(base, exp):
if exp ==0:
return 1
return base*exp_recursive(base, exp-1)
print(exp_recursive(5, 3)) # 125
print(exp_recursive(2, 4)) # 16
print(exp_recursive(5, 1)) # 5
print(exp_recursive(6, 0)) # 1
\ No newline at end of file
def is_array_or_tuple(arg):
if isinstance(arg,list) or isinstance(arg, tuple):
return True
return False
print(is_array_or_tuple('hello')) # False
print(is_array_or_tuple(['hello'])) # True
print(is_array_or_tuple([2, {}, 10])) # True
print(is_array_or_tuple({'a': 2})) # False
print(is_array_or_tuple((1, 2))) # True
print(is_array_or_tuple(set())) # False
\ No newline at end of file
def are_same_type(array):
for x in array:
for y in array:
if type(x) != type(y):
return False
return True
print(are_same_type(['hello', 'world', 'long sentence'])) # True
print(are_same_type([1, 2, 9, 10])) # True
print(are_same_type([['hello'], 'hello', ['bye']])) # False
print(are_same_type([['hello'], [1, 2, 3], [{'a': 2}]])) # True
print(are_same_type([['hello'], set('hello')])) # False
\ No newline at end of file
def is_only_string(string):
if type(string) == str: #isinstance(string, str):
for element in string:
if element == " " or element.isdigit():
return False
return True
return False
print(is_only_string('11')) # False
print(is_only_string('hello')) #True
print(is_only_string(['hello'])) # ? Please handle this case!! Should return False
print(is_only_string('this is a long sentence')) # False
print(is_only_string({'a': 2})) # ? Please handle this case!! Should return False
\ No newline at end of file
def bank(D,W):
return net_amount
print (bank([200, 200, 300], [200]))
print (bank([400,300], [200]))
def bank(D,W):
deposit_array = []
deposit_total = deposit_array.extend(D)
deposit= sum(deposit_total)
withdraw_array =[]
net_amount = deposit-withdraw
return net_amount
print (bank([400,300], [200]))
def new_dict(array):
for x in array:
#for key in result.keys():
return result
print(new_dict([1, 2, 3, 4, 5])) # {1: {2: {3: {4: {5: {}}}}}}
\ No newline at end of file
def nt_dictionary(num):
import random
for key in range(num): #bc exercise states that the number of keys is equal to the input num
while True:
new_key = random.randint(1, 1000) # setting the key
if new_key in dictionary.keys(): #check this logic
continue #check this logic
break #check this logic
dictionary[new_key]= new_key**2 #setting the value
return dictionary
print('Length', len(nt_dictionary(20)))
\ No newline at end of file
#TO DO the manual way
#the package inflect can do this
def write_number(num):
import inflect
p = inflect.engine()
result = p.write_number()
return result
write_number(11) # "eleven"
write_number(2) # "two"
write_number(32) # "thirty-two"
\ No newline at end of file
def is_caught(arg):
if arg.index("C") >= arg.index("m")-3:
return True
return False
print(is_caught('C.....m')) # False
print(is_caught('C..m')) # True
print(is_caught('..C..m')) # True
print(is_caught('...C...m')) # False
print(is_caught('C.m')) # True
\ No newline at end of file
def convert(args):
#convert to an iterable str
for element in args_iterable:
#convert each string a=element to integer
a = sorted(result)
b= a[::-1]
return b
print(convert(429563)) # [9, 6, 5, 4, 3, 2]
print(convert(324)) # [4, 3, 2]
\ No newline at end of file
def letter_counter(string):
for x in string:
if x.isupper():
elif x.islower():
print ("UPPER CASE" + str(count_upper) + "/ LOWER CASE" + str(count_lower))
letter_counter("Hello World!")
# Hello World!
def is_alphanumeric(str):
for element in str:
if type(element) == str or element.isdigit():
return True
elif element == " ":
return False
return False
print(is_alphanumeric('11')) # True
print(is_alphanumeric(['hello'])) # False
print(is_alphanumeric('this is a long sentence')) # False
print(is_alphanumeric({'a': 2})) # False
print(is_alphanumeric("this is string....!!!")) # False
def intersection(a,b):
new_string =a + b
for x in sorted_string:
if x not in result:
result +=x
return result
#to check if the inputs are only letters (ie no spaces or digits) AND if they are not equal
a = 'xyaabbbccccdefww'
b = 'xxxxyyyyabklmopq'
x = 'abcdefghijklmnopqrstuvwxyz'
print(intersection(a, b)) # abcdefklmopqwxy
print(intersection(a, x)) # abcdefghijklmnopqrstuvwxyz
\ No newline at end of file
def split_the_bill(arg):
for value in arg.values(): #iterate through values
average = sum/len(arg)
#itarate through whole object and replace the values of the keys:
for key, value in arg.items():
result[key] =value- average
return result
group = {
'Amy': 20,
'Bill': 15,
'Chris': 10
print(split_the_bill(group)) # { 'Amy': -5, 'Bill': 0, 'Chris': 5 }
def is_string(string):
if isinstance(string, str):
print (True)
print (False)
def zero_sum(array):
for x in array:
for y in array[1::]:
if x== -y :
reverse_output= output[::-1]
#bc of NOTE below ahd to create an interim array and see if those modules existed already in the nested module results object
if output not in result and reverse_output not in result:
return result
print(zero_sum([1, 5, 0, -5, 3, -1])) # [[0, 5], [1, 3], [2, 2]]
print(zero_sum([1, -1])) # [[0, 1]]
print(zero_sum([0, 4, 3, 5])) # [[0, 0]]
#NOTE: in a nested array, or nested tutle, not in only recognized exact modules and does not see numbers inside nested modules
#tests to demonstrate the above
def test(array):
if (array) not in [[2, 3], (5, 6), 9, 1]:
return False
return True
print (test([2,3]))
print (test([3,2]))
print (test(2))
print (test(9))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment