Skip to content

Instantly share code, notes, and snippets.

function sortByName() {
return function(x, y) {
return ((x.fullname == y.fullname) ? 0 : ((x.fullname > y.fullname) ? 1 : -1 ));
}
}
def _available_moves(game_state):
#return a list of available moves on the board.
return [i for i, j in enumerate(game_state) if j != 'X' and j != 'O']
def fbgen(n):
for i in n:
if i % 15 == 0: yield 'Fizzbuzz'
elif i % 3 == 0: yield 'Fizz'
elif i % 5 == 0: yield 'Buzz'
else: yield i
if __name__ == '__main__':
for fb in fbgen(range(1,100)):
print fb
def sequence_gen(n):
ret = 0
i = 0
while i < n:
yield ret
ret = ((ret**2) + 45) % 1000000007
i += 1
'''
Project Euler problem 477
url: https://projecteuler.net/problem=477
'''
import sys
def sequence_gen(n):
ret = 0
i = 0
while i < n:
[{u'canonical_url': u'www.local.cmgsharedcontent.com:8000/gallery/news/national/photos-mudslide-block-both-directions-roadway-near/gCJnS/',
u'categories': [u'/News/National', u'/News', u'/News/Disasters'],
u'content_created': u'2014-03-22T19:57:12Z',
u'content_modified': datetime.datetime(2014, 3, 27, 7, 9, 4, 404000, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>),
u'details': {u'django_ct': u'photos.medleygallery',
u'django_id': u'118454',
u'id': u'photos.medleygallery.118454',
u'indexed_date': datetime.datetime(2014, 8, 22, 16, 20, 49, 177000, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>),
u'page_title': u'PHOTOS: Deadly mudslide in Washington'},
u'first_created': u'2014-03-22T19:57:12Z',
from medley.extensions.models.story import MedleyStory
for story in MedleyStory.objects.all():
story.reindex(using='solr4_aws')
from medley.list_o_rama.models.auto import AutomaticList
myList = AutomaticList.objects.get(id=10)
myList.perform_search()
In [1]: from medley.medley_lists.models import FastAutoList
In [2]: myFAL = FastAutoList.objects.get(id=57)
In [3]: res = myFAL.perform_search()
In [4]: 'teaseimage_url' in res[0].keys()
Out[4]: True
In [5]: 'teaseimage_url' in res[1].keys()
# Not "Pythonic"
if 'keyname' in item.keys():
return item['keyname']
return None
# Is "Pythonic"
try:
return item['keyname']
except KeyError:
pass