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 os | |
import shutil | |
def make_dir(name): | |
raise Exception() | |
if not os.path.exists("target /" + name): | |
os.mkdir("target /" + name) | |
def main(): | |
file_list = os.listdir("./files") |
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 main(): | |
f = open("twain.txt") | |
text = f.read() | |
f.close() | |
text = text.lower() | |
num_letters = [0] * 26 |
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
#!/usr/bin/env python | |
from math import sqrt | |
def pearson(pairs): | |
# Takes in a list of pairwise ratings and produces a pearson similarity | |
series_1 = [float(pair[0]) for pair in pairs] | |
series_2 = [float(pair[1]) for pair in pairs] | |
sum1 = sum(series_1) | |
sum2 = sum(series_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
#define XPIN 2 | |
#define YPIN 1 | |
#define ZPIN 0 | |
#define MAX_POINTS 48 | |
#define ACTUAL_POINTS 16 | |
unsigned long readTimer = 0; | |
unsigned long reportTimer = 0; | |
unsigned long lastTimer = 0; |
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
Exercise 02: Math and functions | |
======= | |
Introduction | |
-------- | |
We're taught mathematical notation using 'infix' notation, that is, the operator goes between the numbers: | |
eg: In '3 + 2', the operator, '+', goes between the operands, 3 and 2. | |
An alternate notation for math is called 'prefix'. As you might have guessed, in prefix notation, the operator goes in front of the operands: |
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 count(filename): | |
f = open(filename) | |
text = f.read() | |
text.lower() | |
letters = [0] * 26 | |
for letter in text: | |
index = ord(letter) - ord("a") | |
if index >= 0 and index < 26: |
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
Exercise 05: Files, Creative uses of lists | |
========================================== | |
Introduction | |
------------ | |
Files can be opened using the .open method, and then processed one character at a time as a bytestream using the .read method with an argument of 1: | |
f = open("myfile.txt") | |
firstletter = f.read(1) | |
f.close() |
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 custom_len(input_list): | |
"""custom_len(input_list) imitates len(input_list)""" | |
count = 0 | |
for item in input_list: | |
count += 1 | |
return count | |
def custom_remove(input_list, value): | |
"""custom_remove(input_list, value) imitates input_list.remove(value)""" | |
for i in range(custom_len(input_list)): |
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 case(object): | |
EMPTY_CASE = (None for x in [1]) | |
def __init__(self, *args): | |
self.cases = args | |
self.used = False | |
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
def cross(A, B): | |
"Cross product of elements in A and elements in B." | |
return [a+b for a in A for b in B] | |
digits = '123456789' | |
rows = 'ABCDEFGHI' | |
cols = digits | |
squares = cross(rows, cols) | |
unitlist = ([cross(rows, c) for c in cols] + | |
[cross(r, cols) for r in rows] + |