Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 61b8b54c authored by Loic Huder's avatar Loic Huder
Browse files

Changed example of dict comprehension

parent 3f7d1271
Pipeline #32973 passed with stage
in 57 seconds
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -185,7 +185,7 @@ ...@@ -185,7 +185,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -214,7 +214,7 @@ ...@@ -214,7 +214,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
"['a', 'e']" "['a', 'e']"
] ]
}, },
"execution_count": 7, "execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -253,7 +253,7 @@ ...@@ -253,7 +253,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
"[(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]" "[(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]"
] ]
}, },
"execution_count": 1, "execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -300,7 +300,7 @@ ...@@ -300,7 +300,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -338,10 +338,8 @@ ...@@ -338,10 +338,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 11,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# 2 equivalent notations to define an empty tuple (not very useful...)\n", "# 2 equivalent notations to define an empty tuple (not very useful...)\n",
...@@ -357,7 +355,7 @@ ...@@ -357,7 +355,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -366,7 +364,7 @@ ...@@ -366,7 +364,7 @@
"['count', 'index']" "['count', 'index']"
] ]
}, },
"execution_count": 10, "execution_count": 12,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -378,7 +376,7 @@ ...@@ -378,7 +376,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -414,7 +412,7 @@ ...@@ -414,7 +412,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -452,10 +450,8 @@ ...@@ -452,10 +450,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 15,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"s0 = set()" "s0 = set()"
...@@ -463,7 +459,7 @@ ...@@ -463,7 +459,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -472,7 +468,7 @@ ...@@ -472,7 +468,7 @@
"{1, 3}" "{1, 3}"
] ]
}, },
"execution_count": 14, "execution_count": 16,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -483,7 +479,7 @@ ...@@ -483,7 +479,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -492,7 +488,7 @@ ...@@ -492,7 +488,7 @@
"{1, 3}" "{1, 3}"
] ]
}, },
"execution_count": 15, "execution_count": 17,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -503,7 +499,7 @@ ...@@ -503,7 +499,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -537,7 +533,7 @@ ...@@ -537,7 +533,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -567,15 +563,15 @@ ...@@ -567,15 +563,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"integer remove from the list: 3\n", "integer remove from the list: 12\n",
"shuffled list: [4, 2, 5, 16, 15, 6, 9, 18, 8, 7, 13, 11, 17, 14, 12, 0, 19, 1, 10]\n" "shuffled list: [6, 15, 7, 1, 0, 8, 2, 19, 10, 17, 11, 3, 9, 14, 16, 4, 18, 13, 5]\n"
] ]
} }
], ],
...@@ -614,16 +610,16 @@ ...@@ -614,16 +610,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"3" "12"
] ]
}, },
"execution_count": 4, "execution_count": 21,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -668,7 +664,7 @@ ...@@ -668,7 +664,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -688,7 +684,7 @@ ...@@ -688,7 +684,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -719,7 +715,7 @@ ...@@ -719,7 +715,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -738,7 +734,7 @@ ...@@ -738,7 +734,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -747,7 +743,7 @@ ...@@ -747,7 +743,7 @@
"'value1'" "'value1'"
] ]
}, },
"execution_count": 21, "execution_count": 25,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -758,7 +754,7 @@ ...@@ -758,7 +754,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -777,7 +773,7 @@ ...@@ -777,7 +773,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -786,7 +782,7 @@ ...@@ -786,7 +782,7 @@
"'value1'" "'value1'"
] ]
}, },
"execution_count": 23, "execution_count": 27,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -815,7 +811,7 @@ ...@@ -815,7 +811,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -834,7 +830,7 @@ ...@@ -834,7 +830,7 @@
" 'values']" " 'values']"
] ]
}, },
"execution_count": 24, "execution_count": 28,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -857,7 +853,7 @@ ...@@ -857,7 +853,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -879,7 +875,7 @@ ...@@ -879,7 +875,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -900,7 +896,7 @@ ...@@ -900,7 +896,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -921,21 +917,23 @@ ...@@ -921,21 +917,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"{'key0': 'value0', 'key1': 'value1', 'key2': 'value2'}\n" "{'key0': 'value0', 'key1': 'value1', 'key2': 'value2'}\n",
"{'key0': 'VALUE0', 'key1': 'VALUE1', 'key2': 'VALUE2'}\n"
] ]
} }
], ],
"source": [ "source": [
"# dict comprehension (here for the \"inversion\" of the dictionary)\n", "# dict comprehension (here to change the case of values)\n",
"print(d)\n", "print(d)\n",
"d1 = {v: k for k, v in d.items()}" "d1 = {k: v.upper() for k, v in d.items()}\n",
"print(d1)"
] ]
}, },
{ {
...@@ -953,10 +951,8 @@ ...@@ -953,10 +951,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 33,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"text = 'abbbcc'" "text = 'abbbcc'"
...@@ -975,14 +971,14 @@ ...@@ -975,14 +971,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"text= Las Vegas Overlook Loop is a 6.3 mile loop trail located near Las Vegas counts= {'L': 3, 'a': 8, 's': 5, ' ': 13, 'V': 2, 'e': 6, 'g': 2, 'O': 1, 'v': 1, 'r': 3, 'l': 5, 'o': 7, 'k': 1, 'p': 2, 'i': 3, '6': 1, '.': 1, '3': 1, 'm': 1, 't': 2, 'c': 1, 'd': 1, 'n': 1}\n" "text= abbbcc counts= {'a': 1, 'b': 3, 'c': 2}\n"
] ]
} }
], ],
...@@ -1018,7 +1014,7 @@ ...@@ -1018,7 +1014,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1026,20 +1022,20 @@ ...@@ -1026,20 +1022,20 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"len(s) = 7160000, nbkeys 33 base, count, count_count, except, colection.counter\n", "len(s) = 7160000, nbkeys 33 base, count, count_count, except, colection.counter\n",
"1 loop, best of 5: 550 ms per loop\n", "747 ms ± 51.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"1 loop, best of 5: 495 ms per loop\n", "692 ms ± 42.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"10 loops, best of 5: 146 ms per loop\n", "286 ms ± 9.76 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"1 loop, best of 5: 488 ms per loop\n", "667 ms ± 25.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"1 loop, best of 5: 265 ms per loop\n", "355 ms ± 11.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"1 loop, best of 5: 450 ms per loop\n", "572 ms ± 9.46 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"with split\n", "with split\n",
"len(s) = 1100000, nbkeys 90 base, count, count_count, except, colection.counter\n", "len(s) = 1100000, nbkeys 90 base, count, count_count, except, colection.counter\n",
"10 loops, best of 5: 123 ms per loop\n", "142 ms ± 2.51 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"10 loops, best of 5: 113 ms per loop\n", "147 ms ± 7.07 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"1 loop, best of 5: 992 ms per loop\n", "1.71 s ± 184 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"10 loops, best of 5: 101 ms per loop\n", "126 ms ± 4.58 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"10 loops, best of 5: 62.3 ms per loop\n", "78.9 ms ± 1.87 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"1 loop, best of 5: 449 ms per loop\n" "658 ms ± 65.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
] ]
} }
], ],
...@@ -1119,10 +1115,8 @@ ...@@ -1119,10 +1115,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 36,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -1163,7 +1157,7 @@ ...@@ -1163,7 +1157,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1209,7 +1203,7 @@ ...@@ -1209,7 +1203,7 @@