%reload_ext nbtutor
%%nbtutor -r -f -d 5
class Foo(object):
a = 10
def __init__(self, b):
self.b = b
def dostuff(self, x):
self.b += x
return self.b
foo = Foo(10)
ans = foo.dostuff(100)
print(ans)
%%nbtutor -r -f
import math
def fubar(eggs, spam):
foo = eggs * spam
return foo
bar = fubar(0.1, 103)
print(bar)
%%nbtutor -r -f -d 5
def fib(n):
a, b = 1, 1
for i in range(n):
yield a
a, b = b, a+b
ans = list(fib(5))
%%nbtutor -r -f -d 15
def fib(n):
if n <= 2:
return [1] * n
prev = fib(n-1)
return prev + [prev[-2] + prev[-1]]
ans = fib(5)
print(ans)
%%nbtutor -r -f -d 15
a = {'foo': 100}
keys, values = zip(*a.items())
print(list(keys), list(values))
for i in a:
print(i)
items = sorted(a.items(), key=lambda x: x[0])
keys, values = zip(*items)
print(list(keys), list(values))