-
-
Save hasibzunair/b0d7509342e5ffe4f27d1fa242613334 to your computer and use it in GitHub Desktop.
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 what(x): | |
# jibberish | |
add = x+x | |
new = add -1 | |
n2 = new * new | |
div = n2/2 | |
import pdb; pdb.set_trace() | |
return div | |
def binary_search(array, val): | |
# simple binary search implementation | |
import pdb; pdb.set_trace() | |
arr = array | |
min_idx = 0 | |
max_idx = len(array) | |
while min_idx < max_idx: | |
middle_idx = (min_idx + max_idx) // 2 | |
if array[middle_idx] == val: | |
return middle_idx | |
elif array[middle_idx] < val: | |
min_idx = middle_idx + 1 | |
else: | |
max_idx = middle_idx | |
return None | |
# test and debug binary search | |
x = [5, 4, 3, 6, 1] | |
binary_search([1,2,4,7,10,11], val=10) | |
''' | |
In pdb, set the following mythical commands | |
''' | |
# value --> prints variable | |
# s --> Execute the current line | |
# n --> Continue execution until the next line in the current function is reached or it returns. | |
# ll -> View the whole source code(function) | |
# l -> 11 lines around the set_trace() block | |
# r --> Continue execution until the current function returns. This let's you examine the final outcome of a function. | |
# c -> exit pdb debugger |
Author
hasibzunair
commented
Feb 3, 2019
•
- l(ist) - Displays 11 lines around the current line or continue the previous listing.
- s(tep) - Execute the current line, stop at the first possible occasion.
- n(ext) - Continue execution until the next line in the current function is reached or it returns.
- b(reak) - Set a breakpoint (depending on the argument provided).
- r(eturn) - Continue execution until the current function returns.
- q - to quit
- h - for help
import pdb; pdb.set_trace()
import matplotlib.pyplot as plt
plt.imshow(img); plt.show()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment