Created
July 4, 2012 15:34
-
-
Save kristopherjohnson/3047911 to your computer and use it in GitHub Desktop.
Python snippets
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 | |
if name == 'Foo': | |
foo() | |
elif name == "Bar': | |
bar() | |
else: | |
wtf() | |
numbers = ['one', 'two', 'three'] | |
for x in numbers: | |
do_something(x); | |
for i in range(len(numbers)): | |
do_something(numbers[i]) | |
def a_function(x): | |
print x | |
print [n*3 for n in range(10) if n%2 == 1] # prints "[3, 9, 15, 21, 27]" | |
# create a matrix with five rows and six columns, initialized with zeros | |
matrix_5_by_6 = [[0 for col in range(6)] for row in range(5)] | |
f = open("myfile.txt") | |
for line in f: | |
process(line) | |
import re | |
result = re.match(pattern, string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://undefinedvalue.com/2012/02/27/my-python-cheatsheet