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
import datetime | |
import thread | |
import _strptime | |
[thread.start_new_thread(lambda : datetime.datetime.strptime("20161015","%Y%m%d"), ()) for _ in range(2)] |
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
import datetime | |
import thread | |
[thread.start_new_thread(lambda : datetime.datetime.strptime("20161015","%Y%m%d"), ()) for _ in range(2)] |
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
def handler_function(event, context): | |
# event - some event data (usually dict) | |
# context - runtime information | |
return 'ok' |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
>>> import bisect | |
>>> from timeit import timeit | |
>>> from random import randint | |
>>> def bisect_sort(): | |
>>> l = [randint(0, 300000) for x in xrange(1000000)] | |
>>> bisect.bisect_left(l, 42) | |
>>> print timeit(bisect_sort, number=100) | |
117.30470705 |
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
>>> import heapq | |
>>> from random import randint | |
>>> my_heap = [] | |
>>> for _ in xrange(20): | |
>>> heapq.heappush(my_heap, randint(0, 3000)) | |
>>> print my_heap | |
[134, 541, 156, 895, 706, 1700, 427, 2049, 1108, 1092, 1895, 2807, 2469, 811, 717, 2962, 2992, 2356, 1935, 2834] |
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
>>> from __future__ import division | |
>>> from collections import namedtuple | |
>>> json_data = { | |
>>> "id": 63082999, | |
>>> "title": "Le retour", | |
>>> "upload_date": "2013-04-01 08:46:22", | |
>>> "user_id": 13095550, | |
>>> "user_name": "Natalia Chernysheva", | |
>>> "likes": 930, |
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
>>> from collections import defaultdict | |
>>> d = defaultdict(int) | |
>>> for x in ["hell", "camp", "four", "walls", "only", "hell", "pity", "party"]: | |
>>> d[x] += 1 | |
>>> print d["hell"] | |
2 | |
>>> print d["pity"] | |
1 |
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
>>> from collections import deque | |
>>> l = deque([]) | |
>>> for x in xrange(15): | |
>>> l.appendleft(x) | |
>>> l.append(x) | |
>>> print l | |
deque([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) |
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
>>> from random import randint | |
>>> from collections import Counter | |
>>> l = [randint(0, 333) for x in xrange(100)] | |
>>> c = Counter(l) | |
>>> c.most_common(5) | |
[(286, 3), (314, 3), (133, 2), (139, 2), (142, 2)] | |
>>> c[286] | |
3 |
NewerOlder