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
>>> x = [1, 2, 3] | |
>>> y = [4, 5, 6] | |
>>> zipped = zip(x, y) | |
>>> zipped | |
[(1, 4), (2, 5), (3, 6)] | |
>>> x2, y2 = zip(*zipped) | |
>>> x == x2, y == y2 | |
True |
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
#Moving up/down dir structure | |
print os.listdir('.') # current level | |
print os.listdir('..') # one level up | |
print os.listdir('../..') # two levels up | |
# more complex example: | |
# This will walk the file system beginning in the directory the script is run from. It | |
# deletes the empty directories at each level |
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
from time import sleep | |
sleep(5) #sleeps for 5 seconds |
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
if ($('#keks').html()) { | |
// Do something to remedy the situation | |
} |
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
# weird way to represent \' // exit using ctrl-D | |
alias sharecode='curl -si -F '\''content=<-'\'' http://dpaste.com/api/v1/ | grep ^Location: | colrm 1 10' |
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
cd ~/Library/Application\ Support/TextMate/Bundles | |
svn co http://svn.textmate.org/trunk/Review/Bundles/GetBundles.tmbundle/ |
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
find . -name \*.pyc -ok rm {} \; |
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
# To strip/remove HTML tags from an existing string we can use the strip_tags function. | |
# import the strip_tags | |
from django.utils.html import strip_tags | |
# simple string with html inside. | |
html = '<p>paragraph</p>' | |
print html # will produce: <p>paragraph</p> | |
stripped = strip_tags(html) |
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
# Continuation lines can be used, with a backslash as the last character on the | |
# line indicating that the next line is a logical continuation of the line: | |
hello = "This is a rather long string containing\n\ | |
several lines of text just as you would do in C.\n\ | |
Note that whitespace at the beginning of the line is\ | |
significant." | |
print hello |
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
>>> import difflib | |
>>> difflib.SequenceMatcher(None, 'abcde', 'abcde').ratio() | |
1.0 | |
>>> difflib.SequenceMatcher(None, 'abcde', 'zbcde').ratio() | |
0.80000000000000004 | |
>>> difflib.SequenceMatcher(None, 'abcde', 'zyzzy').ratio() | |
0.0 |