Skip to content

Instantly share code, notes, and snippets.

View chuanconggao's full-sized avatar
🧑‍💻

Chuancong Gao chuanconggao

🧑‍💻
  • AWS
View GitHub Profile
@chuanconggao
chuanconggao / prefixspan.py
Last active January 22, 2024 06:00
The original minimal 15 lines implementation of PrefixSpan. Full library at https://github.com/chuanconggao/PrefixSpan-py.
from collections import defaultdict
def frequent_rec(patt, mdb):
results.append((len(mdb), patt))
occurs = defaultdict(list)
for (i, startpos) in mdb:
seq = db[i]
for j in range(startpos + 1, len(seq)):
l = occurs[seq[j]]
@chuanconggao
chuanconggao / anagrams.py
Last active May 14, 2020 19:17 — forked from jmuzsik/anagrams.py
Code for computing anagrams that works on both string and list.
def anagrams(s):
return [s] if len(s) == 0 else [
w[:pos] + s[:1] + w[pos:]
for w in anagrams(s[1:])
for pos in range(len(w) + 1)
]
anagrams("abc")
# returns ['abc', 'bac', 'bca', 'acb', 'cab', 'cba']