-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,244 changed files
with
13,999 additions
and
463 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import math | ||
|
||
|
||
def time_diff(h1, m1, s1, h2, m2, s2): | ||
hour, min, sec = "", "", "" | ||
|
||
return hour, min, sec | ||
|
||
|
||
def f(x, y): | ||
numerator = ( | ||
x ** 2 + (math.e ** (1 / (math.sin(2 * math.pi * y))))) ** (1/3) | ||
denominator = math.log(x ** (1 / 2), 2) | ||
|
||
# round the input to 3 decimal places | ||
|
||
|
||
def shift_right(list_A, list_B): | ||
""" | ||
list A = [1,2,3,4] | ||
list B = [a,b,c] | ||
[a,b,c,1] | ||
""" | ||
|
||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def something(s, k): | ||
""" | ||
split the string s | ||
k = 1 : return all numbers in the array | ||
k = 2 : return all strings in the array | ||
returns ["list", "of, "words"] | ||
or ["1", "4", "6"] | ||
""" | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def flow_chart(a): | ||
""" | ||
write from flow chart | ||
""" | ||
l1, l2, l3 = [], [], [] | ||
|
||
i = 0 | ||
while i < len(a): | ||
if a[i] % 2 == 0: | ||
l1.append(a[i]) | ||
elif a[i] % 3 == 0: | ||
l2.append(a[i]) | ||
else: | ||
l3.append(a[i]) | ||
|
||
return [l1, l2, l3] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# file input | ||
|
||
def split_words(filename): | ||
""" | ||
read the file, clean the words (only alnums), convert to lowercase and return them as an array | ||
returns ["the", "clean", "words"] | ||
""" | ||
|
||
pass | ||
|
||
|
||
def get_word_frequency(w): | ||
""" | ||
returns the word frequencies, sorted by descending order of the frquencies and character order | ||
returns [["the", 2], ["a", 1], ["words", 1]] | ||
""" | ||
pass | ||
|
||
|
||
def cut_threshold(w, thresh=2): | ||
""" | ||
returns the word frequency array, but cut by a threshold | ||
input | ||
[["the", 2], ["a", 1], ["words", 1]] | ||
1 | ||
returns | ||
[["the", 2]] | ||
""" | ||
pass | ||
|
||
|
||
def main(): | ||
# call all functions | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# bwt econding | ||
# https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform |
Binary file not shown.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
midterm/lesson02 - string.py → exam preparation/02 - string.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# TODO Provide more examples and explanations | ||
|
||
# String | ||
|
||
s = "Hello" | ||
|
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
midterm/lesson04 - looping.py → exam preparation/04 - looping.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# TODO Provide more advanced examples and explanations | ||
|
||
# Repetition | ||
|
||
# 'While' loop | ||
|
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# Dictionary | ||
|
||
# Dictionaries are used to store data values in key:value pairs. | ||
|
||
# ================================= | ||
|
||
# Accessing data from a dictionry | ||
|
||
# A dictionary is kinda like a list | ||
# For a list, you use an index to get a value | ||
|
||
import time | ||
a = [1, 2, 3, 4] | ||
print(a[1]) # 2 | ||
|
||
# For a dictionary, you use a key to get a value | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
print(a["one"]) # 1 | ||
|
||
|
||
grades = {"6130186221": "A", "6230221221": "A", | ||
"6231009821": "B", "6230543921": "C", | ||
"6230431521": "B", "6230276821": "A"} | ||
|
||
print(grades["6130186221"]) # A | ||
|
||
# You can also use a variable as a key | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
key = "one" | ||
print(a[key]) # 1 | ||
|
||
# ================================= | ||
|
||
# Assigning data to a dictionary | ||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
a["five"] = 5 | ||
|
||
b = "six" | ||
a[b] = 6 | ||
|
||
# ================================= | ||
|
||
# Keys and Values can be any type of data | ||
|
||
my_dict = {"weather": "sunny", "temperature": 25, "wind": "calm", | ||
"humidity": 0.5, "id101": [1, 2, 3, 4], 101: 100, } | ||
|
||
|
||
# But floating point keys are not encouraged | ||
|
||
my_dict = {0.1: 'a', 0.2: 'b', 0.3: 'c', 0.4: 'd'} | ||
k = 0.1 | ||
print(my_dict[k]) # a | ||
k += 0.1 # 0.2 | ||
print(my_dict[k]) # b | ||
k += 0.1 # 0.30000000000000001 | ||
print(my_dict[k]) # erro | ||
|
||
# ================================= | ||
|
||
# Checking if k is in a dictionary | ||
# Used for checking if a key is in a dictionary | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
print("one" in a) # True | ||
print("five" in a) # False | ||
|
||
# ================================= | ||
|
||
# Example: Checking if id is in dictionary | ||
|
||
|
||
def read_data(): | ||
x = input().split(", ") | ||
d = {"ID": x[0], | ||
"Name": x[1], | ||
"Birthdate": [int(x[2]), int(x[3]), int(x[4])]} | ||
return d | ||
|
||
|
||
student1 = {"ID": "5830000021", | ||
"Name": "Pranpriya M.", | ||
"Birthdate": [27, 3, 1997]} | ||
student2 = read_data() | ||
print(student2) | ||
# ================================= | ||
|
||
|
||
# Looping over a dictionary | ||
# You can loop over a dictionary using a for loop | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
for key in a: | ||
print(key, a[key]) | ||
|
||
# OUTPUT | ||
# one 1 | ||
# two 2 | ||
# three 3 | ||
# four 4 | ||
|
||
# ================================= | ||
|
||
# dict.keys(), dict.values(), dict.items() | ||
# Returns a list of keys, values, or key:value pairs | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
print(a.keys()) # ['one', 'two', 'three', 'four'] | ||
print(a.values()) # [1, 2, 3, 4] | ||
print(a.items()) # [('one', 1), ('two', 2), ('three', 3), ('four', 4)] | ||
|
||
|
||
# You can also loop over a dictionary using the items() method | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
for key, value in a.items(): # destructing from a list | ||
print(key, value) | ||
|
||
# ================================= | ||
|
||
# Bonus | ||
|
||
# looping over a list of sorted keys | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
|
||
for key in sorted(a.keys()): | ||
print(key, a[key]) | ||
|
||
|
||
# sorting dictionary.items() by value | ||
|
||
a = {"one": 1, "two": 2, "three": 3, "four": 4} | ||
for v, k in sorted([(v, k) for k, v in a.items()]): | ||
print(v, k) | ||
|
||
# ================================= | ||
|
||
# Bonus: Dictionary Comprehension | ||
|
||
source = [("one", 1), ("two", 2), ("three", 3), ("four", 4)] | ||
d = {k: v for k, v in source} | ||
|
||
# ================================= | ||
|
||
# Example: Dict access time | ||
|
||
|
||
def search_all(X): | ||
b = time.time() | ||
n = len(X) | ||
for i in range(n): | ||
if i in X: # True | ||
pass | ||
for i in range(n): | ||
if (n+1) in X: # False | ||
pass | ||
print(time.time() - b) | ||
|
||
|
||
n = 10000 | ||
L = [] | ||
for i in range(n): | ||
L.append(i) | ||
D = {} | ||
for i in range(n): | ||
D[i] = i | ||
|
||
search_all(L) | ||
search_all(D) |
Oops, something went wrong.