Created
August 13, 2021 03:32
-
-
Save angeloped/f2a474771ff049713a7917e316027e2b to your computer and use it in GitHub Desktop.
A simple text compressor (demo).
This file contains hidden or 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
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