Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sethbunke/6aa0c144baaf08acb53db91331eed285 to your computer and use it in GitHub Desktop.

Select an option

Save sethbunke/6aa0c144baaf08acb53db91331eed285 to your computer and use it in GitHub Desktop.
Create text to integer and integer to text mappings
create_text_lookup_tables = lambda text: ({c: i for i, c in enumerate(set(text))}, dict(enumerate(set(text))))
vocab_to_int, int_to_vocab = create_text_lookup_tables(['this','is','my','test'])
print(vocab_to_int)
#{'is': 0, 'my': 1, 'this': 2, 'test': 3}
print(int_to_vocab)
#{0: 'is', 1: 'my', 2: 'this', 3: 'test'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment