Created
June 26, 2015 14:50
-
-
Save JimHaughwout/b259986d4c334b08bb48 to your computer and use it in GitHub Desktop.
Dicts for Mapping
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
#! /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