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 codecs | |
import sys | |
from bs4 import BeautifulSoup | |
wall_file = open(sys.argv[1], "r") | |
wall = BeautifulSoup(wall_file, 'html.parser') | |
comment_divs = wall.find_all(class_="comment") | |
comments = [div.string for div in comment_divs] |
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
blocks = [] | |
while True: | |
block = f.read(32) | |
if block == '': | |
break | |
blocks.append(block) | |
from functools import partial | |
blocks = [] |
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
for r in restaurants: | |
if r.score >= 4.5: | |
return r.name | |
return "let's cook!" | |
first = next((r.name for r in restaurants if r.score > 4.5), "let's cook!") |
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
for c in colors: | |
if c == 'blue': | |
return True | |
return False | |
'blue' in colors |
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
for x in numbers: | |
if x % 2 == 0: | |
print "it's alright!" | |
break | |
else: | |
raise ValueError |
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
for i, c in enumerate(shuffled_numbers): | |
if x == 2: | |
return i | |
shuffled_numbers.index(2) |
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
dict(izip(keys, values)) | |
# reuses the same tuple! |
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
for x in numbers: | |
if x % 2 == 0: | |
return True | |
return False | |
any(x % 2 == 0 for x in numbers) | |
# it's a generator, stops at the first occurrence |
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
for x in numbers: | |
if x % 2 != 0: | |
return False | |
return True | |
all(x % 2 == 0 for x in numbers) | |
# it's a generator, stops at the first occurrence |
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 x % 2 == 0: | |
return True | |
return False | |
bool(x % 2 == 0) |
OlderNewer