From 2985cc355e868951a2755be23d3503b05ba17ea7 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 3 Nov 2013 11:42:51 +0000 Subject: [PATCH] Now using the built-in functools.lru_cache instead of my own memo function --- segment.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/segment.py b/segment.py index 08bc0aa..712895b 100644 --- a/segment.py +++ b/segment.py @@ -4,19 +4,10 @@ import collections from math import log10 import itertools import sys +from functools import lru_cache sys.setrecursionlimit(1000000) -def memo(f): - "Memoize function f." - table = {} - def fmemo(*args): - if args not in table: - table[args] = f(*args) - return table[args] - fmemo.memo = table - return fmemo - -@memo +@lru_cache() def segment(text): """Return a list of words that is the best segmentation of text. """ -- 2.34.1