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
bands = [{'name': 'sunset rubdown', 'country': 'UK', 'active': False}, | |
{'name': 'women', 'country': 'Germany', 'active': False}, | |
{'name': 'a silver mt. zion', 'country': 'Spain', 'active': True}] | |
def assoc(_d, key, value): | |
from copy import deepcopy | |
d = deepcopy(_d) | |
d[key] = value | |
return d |
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
def zero(s): | |
if s[0] == "0": | |
return s[1:] | |
def one(s): | |
if s[0] == "1": | |
return s[1:] | |
""" | |
def rule_sequence(s, rules): |
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
people = [{'name': 'Mary', 'height': 160}, | |
{'name': 'Isla', 'height': 80}, | |
{'name': 'Sam'}] | |
""" | |
height_total = 0 | |
height_count = 0 | |
for person in people: | |
if 'height' in person: | |
height_total += person['height'] |
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
# Unfunctional version: | |
names = ['Mary', 'Isla', 'Sam'] | |
''' | |
for i in range(len(names)): | |
names[i] = hash(names[i]) | |
print names # => [6306819796133686941, 8135353348168144921, -1228887169324443034] | |
''' |
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
# shopping_list = ["apple", "toothbrush", "banana", "black lava"] | |
# shopping_list.append("cheese") | |
# shopping_list.reverse() | |
# print("Shopping List") | |
# for shopping_list_item in shopping_list: | |
# if len(shopping_list_item)<7 or shopping_list_item=="black lava": | |
# print("-" + shopping_list_item) | |
# if (shopping_list_item.get("done")==False): | |
# print ("-" + shopping_list_item.get("name")) | |
# else: |
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
shopping_list = ["apple", "toothbrush", "banana", "black lava"] | |
shopping_list.append("cheese") | |
shopping_list.reverse() | |
print("Shopping List") | |
for shopping_list_item in shopping_list: | |
if len(shopping_list_item)<7 or shopping_list_item=="black lava": | |
print("-" + shopping_list_item) |
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
### Keybase proof | |
I hereby claim: | |
* I am maryrosecook on github. | |
* I am maryrosecook (https://keybase.io/maryrosecook) on keybase. | |
* I have a public key whose fingerprint is 59DB 7EF4 2BAC 5D67 22FB F7DA 7DFF 4628 A3F1 83AF | |
To claim this, I am signing this object: |
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
e |
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
# A practical introduction to functional programming | |
Many functional programming articles teach abstract functional techniques. That is, composition, pipelining, higher order functions. This one is different. It shows examples of imperative code that people write every day and translates them to a functional style. | |
The imperative examples are all loops. The first section of the article takes short, data transforming loops and translates them into functional maps and reduces. The second section takes longer loops, breaks them up into units and makes each unit functional. The third section takes a loop that is a long series of successive data transformations and decomposes it into a functional pipeline. | |
The examples are in Python, because many people find Python easy to read. A number of the examples eschew pythonicity in order to demonstrate functional techniques common to many languages: map, reduce, pipeline. | |
## A guide rope |
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
block_size = 16 | |
blocks = [] | |
a_size = 128 | |
b_size = 32 | |
a = [0, 1, 2] | |
b = [0, 1, 2] | |
print a == b | |
def memoise(fn): |