Skip to content

Instantly share code, notes, and snippets.

@michaelcoyote
Last active June 19, 2017 21:05
Show Gist options
  • Save michaelcoyote/2a311afaeaa5dec4a5b05689b1bb8e21 to your computer and use it in GitHub Desktop.
Save michaelcoyote/2a311afaeaa5dec4a5b05689b1bb8e21 to your computer and use it in GitHub Desktop.
Python dictonary defaults
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"one is: foo\n",
"two is: None\n",
"three is: bar\n"
]
}
],
"source": [
"test_dict = { 'one': 'foo', 'two': None }\n",
"for n in [ 'one', 'two', 'three']:\n",
" print '{} is: {}'.format(n, test_dict.get(n, 'bar'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment