# HG changeset patch # User Henry S. Thompson # Date 1781209399 -3600 # Node ID ec914a136771088148a179578c514ec89449477b # Parent fb5e2d06a650e17838edbcc37e110d27098756f4 for 2026 MSc diff -r fb5e2d06a650 -r ec914a136771 lib/python/cc/ex3.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/ex3.py Thu Jun 11 21:23:19 2026 +0100 @@ -0,0 +1,19 @@ +'''Use this to get called by cdx2tsv.py''' + +from collections import defaultdict + +def init(): + global d + d=defaultdict(int) + +def cbf(lang): + global d + if lang=='NA' or ',' in lang: + return + d[lang] += 1 + +def finish(): + global d + for k,v in (sorted(d.items(), key = lambda i : i[1], reverse = True): + print(v, k) + diff -r fb5e2d06a650 -r ec914a136771 lib/python/cc/ex4.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/ex4.py Thu Jun 11 21:23:19 2026 +0100 @@ -0,0 +1,25 @@ +'''Use this to get called by cdx2tsv.py''' + +from collections import defaultdict +from datetime import datetime + +def init(): + global d, N, M + d=defaultdict(lambda: defaultdict(int)) + N = M = 0 + +def cbf(lang,lastmod): + global d, N, M + N += 1 + if lastmod=='NA' or lang=='NA' or ',' in lang: + return + M += 1 + d[datetime.fromtimestamp(int(lastmod)).year][lang] += 1 + +def finish(): + global d, N, M + print("%s with lastmod out of %s in total"%(M, N)) + for k,lv in sorted(d.items(), key = lambda i : i[0]): + print(k, ["%s: %d"%(k,v) for k,v in (sorted(lv.items(), key = lambda i : i[1], + reverse = True))][:10]) +