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 Example: | |
class_attr_1: str = 'attr_1' | |
@classmethod | |
def foo(cls, message: str) -> None: | |
print(f"Message sent from foo: {message}") | |
# access class attribute | |
print(cls.class_attr_1) |
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 Example: | |
@classmethod | |
def foo(cls, message: str) -> None: | |
print(f"Message sent from foo: {message}") | |
@staticmethod | |
def bar(message: str) -> None: | |
print(f"Message sent from bar: {message}") | |
if __name__ == "__main__": |
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 Example: | |
@staticmethod | |
def bar(arg1, arg2, ...): | |
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
class Example: | |
@classmethod | |
def foo(cls, arg1, arg2, ...): | |
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
# DP | |
fib_seq = [0, 1] | |
def fib(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
return 1 | |
if len(fib_seq) == n-1: |
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
# recursion | |
def fib(n): | |
if n==0: | |
return 0 | |
if n==1: | |
return 1 | |
return fib(n-1) + fib(n-2) |
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 fib(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
return 1 | |
fn_2 = 0 | |
fn_1 = 1 | |
for i in range(n-1): |
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 my_gen_1(n): | |
for i in range(n): | |
yield f'g1: {i}' | |
def my_gen_2(n): | |
for j in range(n): | |
yield f'g2: {-j}' | |
def my_gen_master(n): | |
yield from my_gen_1(n) |
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 multiplier(n): | |
step = None | |
result = 1 | |
for i in range(1, n+1): | |
if step is None: | |
step = 1 | |
result *= (i*step) | |
print(f"i:{i}, step={step}") | |
step = yield result |
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 fibonacci_sequence(n): | |
curr_val = 0 | |
next_val = 1 | |
for i in range(n): | |
yield curr_val | |
curr_val, next_val = next_val, curr_val + next_val | |
if __name__ == '__main__': | |
fib_seq = [] | |
for fn in fibonacci_sequence(10): |
NewerOlder