Skip to content

Instantly share code, notes, and snippets.

@JimHaughwout
Created June 26, 2015 14:50
Show Gist options
  • Save JimHaughwout/b259986d4c334b08bb48 to your computer and use it in GitHub Desktop.
Save JimHaughwout/b259986d4c334b08bb48 to your computer and use it in GitHub Desktop.
Dicts for Mapping
#! /usr/bin/env python
"""
Using dictionaries for mapping lookups
See: http://www.tutorialspoint.com/python/python_dictionary.htm
"""
# Use a Python Dictionary for mapping
mapping = {
'CB' : 'Cobra',
'foo' : 'bar',
1 : 'one'
}
# Some sample data for what we want to map
data = 'CB'
# Printing mapped values
print "%s maps to %s" % (data, mapping[data])
print "1 maps to %r" % mapping[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment