Skip to content

Instantly share code, notes, and snippets.

@timrprobocom
Created December 14, 2021 00:56
Show Gist options
  • Save timrprobocom/9a49bb88b3762e82375ed4f14b328e84 to your computer and use it in GitHub Desktop.
Save timrprobocom/9a49bb88b3762e82375ed4f14b328e84 to your computer and use it in GitHub Desktop.
import re
data = [
'atr.i',
'atr i',
'ok',
'test',
'ro bn.',
'ro bn',
'talk 1',
'talk n'
]
clean = [re.sub('[ .,-]','',d) for d in data]
unique = list(set(clean))
for d,c in zip(data,clean):
idx = unique.index(c)
print( f"{d:10} {c:10} {idx:3}" )
# Output:
#
# atr.i atri 5
# atr i atri 5
# ok ok 1
# test test 4
# ro bn. robn 2
# ro bn robn 2
# talk 1 talk1 3
# talk n talkn 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment