This file contains hidden or 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 + number + return | |
def sum_digits(n): | |
""" | |
>>> sum_digits(1234) | |
10 | |
""" | |
if n < 10: | |
return n | |
return n % 10 + sum_digits(n // 10) |
This file contains hidden or 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 Tree: | |
"""A tree.""" | |
def __init__(self, label, branches=[]): | |
self.label = label | |
for branch in branches: | |
assert isinstance(branch, Tree) | |
self.branches = list(branches) | |
def __repr__(self): | |
if self.branches: |
This file contains hidden or 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 Link: | |
"""A linked list.""" | |
empty = () | |
def __init__(self, first, rest=empty): | |
assert rest is Link.empty or isinstance(rest, Link) | |
self.first = first | |
self.rest = rest | |
def __repr__(self): |
This file contains hidden or 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 Link: | |
empty = () | |
def __init__(self, first, rest=empty): | |
assert rest is Link.empty or isinstance(rest, Link) | |
self.first = first | |
self.rest = rest | |
def __repr__(self): | |
if self.rest: |
This file contains hidden or 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 timeit | |
class Link: | |
empty = () | |
def __init__(self, first, rest=empty): | |
self.first = first | |
self.rest = rest | |
def insert_at_start(self, value): |
This file contains hidden or 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 dis | |
def for_version(): | |
y = 0 | |
for x in [1, 2, 3]: | |
y += x * 2 | |
def iter_version(): | |
_gen_ = iter([1, 2, 3]) | |
y = 0 |
This file contains hidden or 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
""" Check your work by running python -m doctest -v popstar.py """ | |
def gen_popstar_name(last_name, street, last_food): | |
"""Your pop star name is your last name followed | |
by the name of the street your grew up on followed | |
by the last food you ate. | |
The only whitespace should be between each of the | |
three parts, and the name should be uppercase. | |
>>> gen_popstar_name("fox", "city lights", "bananas") |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Fibonacci (Animated)</title> | |
<style> | |
body { | |
background: #f3f3f3; | |
} |
This file contains hidden or 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
/* Source: | |
https://www.kaggle.com/nasa/astronaut-yearbook | |
*/ | |
CREATE TABLE astronauts( | |
Name TEXT PRIMARY KEY, | |
Year INTEGER, | |
GroupNum INTEGER, | |
Status TEXT, | |
Birth_Date TEXT, | |
Birth_Place TEXT, |
This file contains hidden or 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
/* | |
Source: | |
https://www.kaggle.com/jacobbaruch/nba-player-of-the-week | |
*/ | |
CREATE TABLE players( | |
Player TEXT, | |
Team TEXT, | |
Conference TEXT, | |
Date TEXT, | |
Position TEXT, |