mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
defaultdict
This commit is contained in:
parent
4d97ce01f2
commit
2fca2d34d7
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1dc4a14b00afc36bd728a4f8d00ea951e5c9376232218e2e5a36e653e875fbe5"
|
||||
"signature": "sha256:75d807f509bd9f76b2e14a5a048cb44852a3318bcd0d95afc95d1c9b2904c078"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -1061,31 +1061,6 @@
|
|||
],
|
||||
"prompt_number": 25
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"def add_element_get(elements):\n",
|
||||
" d = dict()\n",
|
||||
" for e in elements:\n",
|
||||
" d[e] = d.get(e, 1) + 1\n",
|
||||
" return d\n",
|
||||
"\n",
|
||||
"print(add_element_get(rand_ints))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"{1: 17, 2: 10, 3: 11, 4: 7, 5: 9, 6: 14, 7: 13, 8: 13, 9: 15}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 24
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1dc4a14b00afc36bd728a4f8d00ea951e5c9376232218e2e5a36e653e875fbe5"
|
||||
"signature": "sha256:75d807f509bd9f76b2e14a5a048cb44852a3318bcd0d95afc95d1c9b2904c078"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -1061,31 +1061,6 @@
|
|||
],
|
||||
"prompt_number": 25
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"def add_element_get(elements):\n",
|
||||
" d = dict()\n",
|
||||
" for e in elements:\n",
|
||||
" d[e] = d.get(e, 1) + 1\n",
|
||||
" return d\n",
|
||||
"\n",
|
||||
"print(add_element_get(rand_ints))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"{1: 17, 2: 10, 3: 11, 4: 7, 5: 9, 6: 14, 7: 13, 8: 13, 9: 15}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 24
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
Loading…
Reference in New Issue
Block a user