Created
June 2, 2015 21:24
-
-
Save AndrewHoos/411a680ef15ab0e861ef to your computer and use it in GitHub Desktop.
100 Reasons why I love python
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
# ..:77I777777777777777777777I. . | |
# ..?77777777777777777777777777777$+.. | |
# . ~7777777I7777777777777777777777777$~.. | |
# .7I7777...7777777777777777777777777$7+. | |
# .?7777.. ..77777777777777777777777$$7. | |
# .77777 777777777777777777777$$$$$I | |
# .77777.. ...7777777777777777777$$$$$$$$ | |
# .7777777 .77$777777777777777777$$$$$$$$ | |
# .77777777777777777777777777777$$$$$$$$$$ | |
# .77777777777777777777777777$$$$$$$$$$$$$ | |
# .777777777777777777777777$$$$$$$$$$$$$$$ | |
# ....................:7777$$$$$$$$$$$$$$$ | |
# ...,===========================+77$$$$$$$$$$$$$$$$$..:::::::,,... | |
# ..:777777777777777777777777777777777$$$$$$$$$$$$$$$$$$$..============:. | |
# ..~777777777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$..==============. | |
# .77777777777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$..=============== | |
# 7777777777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$..================. | |
# .+777777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$..================, | |
# .7777777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$..================= | |
# .7777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$$$...===============+= | |
# 777777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$Z..:=================~. | |
# 7777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$. .================+++. | |
# 7777777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$I..,=================+++. | |
# 77777777777777777777777$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$....~================+++++: | |
# 777777777777777777777$$7$?.. ......~================+++++++= | |
# 7777777777777777777$$$$............................,====================++++++++ | |
# 7777777777777777777$$....~==~~~~~~~~~~~~==============================+++++++++= | |
# 77777777777777777$$$...~~~~~~~~~~~===================================++++++++++, | |
# 77777777777777$$$$$...~~~~~~~~~~===================================++++++++++++. | |
# 777777777777$$$$$$...~~~~~~==~==================================++++++++++++++=. | |
# .77777777777$$$$$$..:~~~~~~=====================================++++++++++++++.. | |
# .$77777777$$$$$$$$..~~~~~====================================+++++++++++++++++ | |
# .,$77777$$$$$$$$$$..~~~=====================================+++++++++++++++++. | |
# .$$7777$$$$$$$$$$..~======================================++++++++++++++++++. | |
# .$$$$$$$$$$$$$$$..~====================================+++++++++++++++++++.. | |
# .?7$$$$$$$$$$$$..~================================+++++++++++++++++++++~. | |
# ?$$$$$$$$$$$ .=========================================+++++++++++=. | |
# ............ .===================: ................................ | |
# .==================+~................... | |
# .==========================+++++++++++++ | |
# .==========================+++++++++++++ | |
# .========================+++++++++++++++ | |
# .======================++++++....,++++++ | |
# .======================++++=.. .+++++ | |
# .~===================++++++=.. .+++?: | |
# ..=================+++++++++:. +++++. | |
# .===============++++++++++++=~++++++.. | |
# ..:==========+++++++++++++++++++++=. | |
# .++==+=+++++++++++++++++++++.. | |
# ....,==++++++++++++++++=,..... | |
# ....:~+++=:...... | |
# | |
# | |
# 100 Reasons why I love python | |
####################### | |
# Boolean-ish-ness | |
####################### | |
# Reason 1 | |
x = 5 | |
if 0 < x < 10: | |
print('This is incredible') | |
# Reason 2 | |
if 0 == 10-10 == -5+5: | |
print('This is cool too!') | |
# Reason 3 | |
x = None | |
if x is None: | |
print("Isn't that easy to read?") | |
# Reason 4 | |
if 'test' in ['array', 'of', 'many', 'things', 'to', 'test']: | |
print('That was easy') | |
# Reason 5 | |
if 'test' in 'sentence that has test in it.': | |
print('That was easier') | |
# Reason 6 | |
languages_I_know = ['Python', 'JS', 'Objecective-C', 'Swift'] | |
if 'Ruby' not in languages_I_know: | |
print('But that is ok') | |
####################### | |
# Literally Awesome | |
####################### | |
# Reason 7 | |
if r'\\' == '\\\\': | |
print("slashes don't have to be hard") | |
# Reason 8 | |
''' | |
Sometimes strings are longer than others | |
But they should alway be treated with the | |
respect they all deserve | |
''' | |
####################### | |
# Cool Title Here | |
####################### | |
# Reason 9 | |
x = 'Good enough' if 'Ruby' == 'Python' else 'It is not the same' | |
# Reason 10 | |
not_None = None or 'Reason 9' | |
# Reason 11 | |
for i in range(10): | |
if i == 11: | |
break | |
else: | |
print('I was never 11') | |
# Reason 12 | |
try: | |
reason11 = int('11') | |
except Exception as e: | |
print('You suck at casting') | |
else: | |
print('You do not suck at casting') | |
finally: | |
print('Life goes on') | |
# Reason 13 | |
def O_1_sort_function(): | |
pass # work on that later | |
# Reason 14 | |
with ('input.txt') as input_file: | |
pass # do stuff with the file | |
# Reason 15 | |
def vowels(): | |
for vowel in ['a', 'e', 'i', 'o', 'u', 'y']: | |
yield vowel | |
####################### | |
# List Jitsu | |
####################### | |
# Reason 16 | |
some_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
some_numbers[-1] == 10 | |
# Reason 17 | |
some_numbers[1:-1] == [2, 3, 4, 5, 6, 7, 8, 9] | |
# Reason 18 | |
some_odd_numbers = some_numbers[::2] | |
some_odd_numbers == [1, 3, 5, 7, 9] | |
# Reason 19 | |
count_down = some_numbers[::-1] | |
count_down == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
# Reason 20 | |
for index, value in enumerate(['a', 'e', 'i', 'o', 'u']): | |
pass # do some things with vowels | |
# Reason 21 | |
for letter in 'some really long string to break up by characters': | |
if letter in list(vowels()): | |
print letter | |
# Reason 22 | |
for word in 'long sentance with lots of words'.split(' '): | |
pass # interviews are easy this way | |
# Reason 23 | |
log_line = ' Orange FATAL: long line of output '.strip(' ') | |
# Reason 24 | |
keep_the_indent = ' Orange FATAL: long line of output '.rstrip(' ') | |
# Reason 25 | |
keep_the_trailing = ' Orange FATAL: long line of output '.listrip(' ') | |
# Reason 26 | |
format_strings = 'I want {} {}'.format('Apple', 3.1415) | |
####################### | |
# Packing Power | |
####################### | |
# Reason 27 | |
def sum_4_numbers(arg1, arg2, arg3, arg4): | |
return arg1 + arg2 + arg3 + arg4 | |
list_of_4_numbers = [1, 2, 3, 4] | |
sum_4_numbers(*list_of_4_numbers) == 10 | |
# Reason 28 | |
def cool_runnings(*args): | |
for word in args: | |
print 'I see {}!'.format(word) | |
cool_runnings('pride', 'power', "a bad ass mother who won't take crap off of nobody") | |
# Reason 29 | |
def print_affirmation(word=None): | |
print 'I am {}'.format(word) | |
args = {'word': 'so smart'} | |
print_affirmation(**args) | |
# Reason 30 | |
def snide_remarks(**words): | |
for key in words: | |
print '{} is {}'.format(key, words[key]) | |
args = {'Ruby': 'Average', 'Python': 'Exceptional'} | |
snide_remarks(**args) | |
# Reason 31 | |
def do_web_things(): | |
return 501, 'This Reason is not implemented' | |
code, explination = do_web_things() | |
# Reason 32 | |
code, _ = do_web_things() # Ain't no body got time fo' yo' explinations | |
# Reason 33 | |
x, y = 0, 1 | |
x, y = y, x | |
# Reason 34 | |
def debug(function): | |
def debugger(*args, **kwargs): | |
print 'Calling: {}({}, {})'.format(function.__name__, ', '.join(map(str, args)), ','.join(['{}={}'.format(key, repr(kwargs[key])) for key in kwargs])) | |
result = function(*args, **kwargs) | |
print 'Returning: {}'.format(result) | |
return debugger | |
@debug | |
def test(input, **kwargs): | |
return input | |
test(1, key='value') | |
############################ | |
# Prompt This | |
############################ | |
# Reason 35 | |
import this | |
# Reason 36 | |
from __future__ import braces | |
# Reason 37 | |
import antigravity | |
# Reason 38 | |
import pprint | |
pprint.pprint([{'a': 3, 'b': 3.14, 'c': 1, 'd': 2, 'e': 3}, 7, [24, {'apple': [7, 3, {'b': 'funky'}]}]]) | |
# Reason 39 | |
3 + 5 # it is a calculator | |
# Reason 40 | |
2 ** 8 # with exponenets | |
# Reason 41 | |
_ | |
############################ | |
# Built-In Awesomeness | |
############################ | |
# Reason 42 | |
dir('') | |
# Reason 43 | |
help() | |
# Reason 44 | |
import os | |
help(os) | |
# Reason 45 | |
locals() | |
# Reason 46 | |
globals() | |
# Reason 47 | |
zip([1, 2, 3], [-1, -2, -3]) | |
zip(*zip([1, 2, 3], [-1, -2, -3])) | |
# Reason 48 | |
iter([1, 2, 3]) | |
list(iter([1, 2, 3])) == [1, 2, 3] | |
# Reson 49 | |
round(111.11, 1) == 111.1 | |
round(111.11, -1) == 110.0 | |
# Reason 50 | |
reduce(lambda x, y: x*y, [1, 2, 3, 4]) == 24 | |
# Reason 51 | |
map(str, [1, 2, 3, 4]) == ['1', '2', '3', '4'] | |
############################ | |
# Packages Gymnastics | |
############################ | |
# Reason 52 | |
import os | |
# Reason 53 | |
import os as solaris | |
solaris == os | |
# Reason 54 | |
from os import path | |
# Reason 55 | |
from os import path as rainbows | |
os.path == rainbows | |
# Reason 56 | |
from .sys import monkeys | |
# import from sys in the local dir/module instead of system sys | |
# Reason 57 | |
from ..sys import monkeys | |
# import from sys in the parent dir/module instead of system sys | |
# import 58 | |
from sys import * | |
# get all the things | |
# import 59 | |
__all__ = ['solaris'] # limit what we export | |
############################ | |
# From argparse to zipfile | |
############################ | |
# Reason 60 | |
import argparse | |
# Reason 61 | |
import datetime | |
# Reason 62 | |
import glob | |
# Reason 63 | |
import json | |
# Reason 64 | |
import os | |
# Reason 65 | |
import os.path | |
# Reason 66 | |
import plistlib | |
# Reason 67 | |
import re | |
# Reason 68 | |
import subprocess | |
# Reason 69 | |
import zipfile | |
############################ | |
# PyPI for President | |
############################ | |
# Reason 70 | |
# easy_install pip | |
# Reason 71 | |
# pip install requests | |
# Reason 72 | |
# pip install django | |
# Reason 73 | |
# pip install jinja2 | |
# Reason 74 | |
# pip install pep8 | |
# Reason 75 | |
# pip install git+http://github.com/scipy/scipy/ | |
# Reason 76 | |
# pip install git+http://github.com/numpy/numpy/ | |
############################ | |
# PEP 8 | |
############################ | |
# Reason 77 | |
some_value = { | |
'key': 'value', | |
'some other key': { | |
'nested key': 'good times', | |
}, | |
} | |
# Beacause people are stupid | |
############################ | |
# Exotic Objects | |
############################ | |
from collections import * | |
# Reason 78 | |
Point = namedtuple('Point', ['x', 'y']) # It's like a struct, but cooler | |
# Reason 79 | |
{1, 2, 3} == {3, 2, 1} == {1, 1, 2, 3} | |
# Reason 80 | |
ordered = OrderedDict() | |
ordered['first'] = 1 | |
ordered['second'] = 2 | |
for key in ordered: | |
print('{}: {}'.format(key, ordered[key])) | |
# Reason 81 | |
default = defaultdict([]) | |
default['new'].append(1) | |
if defualt['new'] == [1]: | |
print('Just making a list on the fly!') | |
############################ | |
# Comprehend the Basic | |
############################ | |
# Reason 82 | |
my_list = [] | |
my_list.append(1) | |
my_list.append(2) | |
my_list.pop() == 2 | |
my_list.pop() == 1 | |
# Reason 83 | |
my_dict = {} | |
my_dict.get('key that does not exist') is None # my_dict['key'] raises | |
# Reason 84 | |
[number for number in range(100) if number % 2 == 1] | |
# odd numbers 1..99 | |
# Reason 85 | |
{word: len(word) for word in ['red', 'blue', 'green', 'yellow']} | |
# {'blue': 4, 'green': 5, 'yellow': 6, 'red': 3} | |
# Reason 86 | |
[[x for x in range(i+1)] for i in range(5)] | |
# [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
# Reason 87 | |
{i for i in range(10)} | |
# set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | |
############################ | |
# _ is over powered | |
############################ | |
class ReasonExample(object): | |
reasons = { | |
'88': '__iter__', | |
'89': '__contains__', | |
'90': '__len__', | |
'91': '__getitem__', | |
'92': '__call__', | |
'93': '__str__' | |
} | |
# Reason 88 | |
def __iter__(self): | |
return iter(['Reason {}: {}'.format(reason, self.reasons[reason]) for reason in self.reasons]) | |
# Reason 89 | |
def __contains__(self, item): | |
if str(item) in self.reasons: | |
return True | |
# Reason 90 | |
def __len__(self): | |
return len(reasons) | |
# Reason 91 | |
def __getitem__(self, item): | |
return reason.get(str(item)) | |
# Reason 92 | |
def __call__(self): | |
print 'This is only reaspn 92!' | |
# Reason 93 | |
def __str__(self): | |
return 'Reasons: [{}]'.format(', '.join([reason for reason in self.reasons])) | |
reason = ReasonExample() | |
# 88: __iter__ | |
for r in reason: | |
print r | |
# 89: __contains__ | |
print(81 in reason) | |
# 90: __len__ | |
print len(reason) | |
# 91: __getitem__ | |
print r[83] | |
# 92: __call__ | |
r() | |
# 93: __str__ | |
print str(r) | |
#################### | |
# into the bowels | |
#################### | |
# Reason 94 | |
import pdb | |
pdb.set_trace() # c to continue | |
# Reason 95 | |
# w for back trace | |
# Reason 96 | |
# pp for pprint | |
# Reason 97 | |
from Foundation import * | |
objcString = NSMutableString.alloc().init() | |
# Reason 98 | |
print __file__ | |
# Reason 99 | |
print __name__ | |
# Reason 100 | |
print('Hello World!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment