Skip to content

Instantly share code, notes, and snippets.

@angeloped
Created August 13, 2021 03:32
Show Gist options
  • Save angeloped/f2a474771ff049713a7917e316027e2b to your computer and use it in GitHub Desktop.
Save angeloped/f2a474771ff049713a7917e316027e2b to your computer and use it in GitHub Desktop.
A simple text compressor (demo).
text = """aaaa
aaaaaa kjjkj
aaaa kkk a"""
cmprssd = set()
cmprssd_lst = []
for txt in text.split("\n"):
#set.union(cmprssd, set(txt.split()))
cmprssd.update(set(txt.split()))
cmprssd_lst += list(cmprssd)
for wrd in cmprssd_lst:
text = text.replace(wrd, str(cmprssd_lst.index(wrd)))
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment