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 makebold(fn): | |
def wrapped(): | |
return '<b>' + fn() + '</b>' | |
return wrapped | |
def makeitalic(fn): | |
def wrapped(): | |
return '<i>' + fn() + '</i>' | |
return wrapped |
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
from operator import mul | |
def get_products_of_all_ints_except_at_index(lst): | |
""" | |
Returns array of products of all ints except index, for given array of ints. | |
e.g., [1, 7, 3, 4] returns [84, 12, 28, 21] by calculating [7*3*4, 1*3*4, 1*7*4, 1*7*3] | |
""" | |
product_lst = [] | |
for idx in range(len(lst)): | |
except_at_index = lst[:idx] + lst[idx+1:] |
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 | |
# -*- coding: utf-8 -*- | |
import random | |
TEAM_MEMBERS = [ | |
'Marc DaCosta', | |
'Craig Danton', | |
'Mike Flowers', | |
'Hicham Oudghiri', |
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
# There are built-in higher order functions | |
map(add_10, [1, 2, 3]) # => [11, 12, 13] | |
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] | |
# We can use list comprehensions for nice maps and filters | |
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13] | |
[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7] |
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
# in a function definition | |
# *args and **kwargs allow you to pass a variable number of args to a function | |
# *args is for a non-keyworded variable length argument list | |
def test_var_args(f_arg, *argv): | |
print "first normal arg:", f_arg | |
for arg in argv: | |
print "another arg through *argv:", arg | |
# test_var_args('Matt', 1, 2, 3, {}, 'bologna') |
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 xlrd | |
# initialize a workbook | |
workbook = xlrd.open_workbook('<excel filename>') | |
# inspect a workbook's sheets | |
workbook.sheet_names() # returns a list of sheet names | |
# initialize a worksheet | |
worksheet = workbook.sheet_by_name('<sheet name>') |
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
# For sample invalid address of: | |
# "ROYSE CITY TX 75189-, TX 75189-4214" | |
# parse method return object | |
# http://api.geocod.io/v1/parse?q=ROYSE%20CITY%20TX%2075189-,%20TX%2075189-4214&api_key= | |
# { | |
# address_components: { | |
# number: "75189-", | |
# street: "Tx", |
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 codecs | |
import cStringIO | |
import csv | |
import sys | |
import unicodecsv | |
from bs4 import UnicodeDammit | |
######################################################################## |
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
{ | |
"close_windows_when_empty": true, | |
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme", | |
"draw_white_space": "all", | |
"ensure_newline_at_eof_on_save": true, | |
"find_selected_text": true, | |
"font_size": 10.0, | |
"highlight_line": true, | |
"ignored_packages": | |
[ |