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 boto3 | |
import glob | |
import json | |
import os | |
import time | |
from datetime import datetime | |
from tqdm.notebook import tqdm | |
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
# | |
# Setup in your bash with | |
# bash <(curl -sL https://gist.githubusercontent.com/rajmayank/eac2d8e58ceb66b4ef5d319dc1207875/raw/447da14b2d914f46caf23df82ce3e39ebb494b70/setup.sh) | |
# ==== ==== ==== ==== ==== | |
# Setup for Vim | |
echo "set tabstop=2 softtabstop=2 shiftwidth=2 | |
set expandtab | |
set number ruler |
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 FibonacciTill20(): | |
n1, n2 = 0, 1 | |
max_num = 20 | |
while True: | |
n1, n2 = n2, (n1 + n2) | |
if n2 <= max_num: | |
yield n2 | |
else: | |
raise StopIteration |
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
for fibNumber in FibonacciTill20(): | |
print(fibNumber) | |
# 1 | |
# 2 | |
# 3 | |
# 5 | |
# 8 | |
# 13 |
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
fib = FibonacciTill20() | |
print(next(fib)) # 1 | |
print(next(fib)) # 2 | |
print(next(fib)) # 3 | |
print(next(fib)) # 5 | |
print(next(fib)) # 8 | |
print(next(fib)) # 13 | |
print(next(fib)) # Exception: StopIteration |
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 FibonacciTill20: | |
def __init__(self): | |
self.n1, self.n2 = 0, 1 | |
self.max = 20 | |
def __iter__(self): | |
return self | |
def __next__(self): |
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
my_list = ["item #1", "item #2", "item #3", "item #4"] | |
my_list_iter = iter(my_list) | |
print(type(my_list)) # <class 'list'> | |
print(my_list) # ['item #1', 'item #2', 'item #3', 'item #4'] | |
print(type(my_list_iter)) # <class 'list_iterator'> | |
print(my_list_iter) # <list_iterator object at 0x10aa87d60> | |
print(next(my_list_iter)) # item #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
Counter: 1; GoalMultiplier: 5; Expected: 5; Actual: 5 | |
Counter: 2; GoalMultiplier: 5; Expected: 10; Actual: 10 | |
Counter: 3; GoalMultiplier: 5; Expected: 15; Actual: 15 | |
Counter: 4; GoalMultiplier: 5; Expected: 20; Actual: 20 | |
Counter: 5; GoalMultiplier: 5; Expected: 25; Actual: 25 | |
Counter: 6; GoalMultiplier: 10; Expected: 30; Actual: 60 | |
Counter: 7; GoalMultiplier: 10; Expected: 35; Actual: 70 | |
Counter: 8; GoalMultiplier: 10; Expected: 40; Actual: 80 | |
Counter: 9; GoalMultiplier: 10; Expected: 45; Actual: 90 |
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
theGlobalMultiplier = 5 | |
def myMultiplyingGenerator(numbers): | |
for number in numbers: | |
yield number * theGlobalMultiplier | |
for multipliedNumber in myMultiplyingGenerator(range(1,10)): | |
if multipliedNumber > 25: | |
theGlobalMultiplier = 10 | |
print(multipliedNumber) |
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 time | |
def myExpensiveOperations(items): | |
for item in items: | |
time.sleep(2) # The expensive operation | |
yield item ** 2 | |
for item in myExpensiveOperations(range(1,10)): | |
if item > 20: break # We apply the breaks early | |
print(item) # 1, 4, 9, 16 |
NewerOlder