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 python2.7 | |
""" | |
>>> import multigram_search | |
>>> mgs = multigram_search.MultigramSearch([("a", "b", "c"), ("o", "c", "z"), | |
('z','y')]) | |
>>> list(mgs.intersection("hello world you a b c foo".split(" "))) | |
[['a', 'b', 'c']] |
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
""" | |
Simple dictionary caching object that limits the number of cached entries being | |
stored. | |
Micha Gorelick - http://micha.gd/ | |
""" | |
from collections import OrderedDict | |
class LimitedCache(OrderedDict): | |
def __init__(self, maxsize=250): |
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 re | |
def check_winner(board,row=4): | |
try: | |
return re.search(r"([^.|])(\1{%d}|%s)"%(row-1,"|".join(r"(.{%d}\1){%d}"%(len(a[0])+d,row-1) for d in range(-1,2))), "|".join("".join(x) for x in a)).group()[0] | |
except: | |
return "No one" | |
if __name__ == "__main__": | |
a = [ |