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 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -185,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -214,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
......@@ -232,7 +232,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
......@@ -241,7 +241,7 @@
"['a', 'e']"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -253,7 +253,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 9,
"metadata": {},
"outputs": [
{
......@@ -262,7 +262,7 @@
"[(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]"
]
},
"execution_count": 1,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
......@@ -300,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [
{
......@@ -338,10 +338,8 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# 2 equivalent notations to define an empty tuple (not very useful...)\n",
......@@ -357,7 +355,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [
{
......@@ -366,7 +364,7 @@
"['count', 'index']"
]
},
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
......@@ -378,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [
{
......@@ -414,7 +412,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 14,
"metadata": {},
"outputs": [
{
......@@ -452,10 +450,8 @@
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"s0 = set()"
......@@ -463,7 +459,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 16,
"metadata": {},
"outputs": [
{
......@@ -472,7 +468,7 @@
"{1, 3}"
]
},
"execution_count": 14,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -483,7 +479,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 17,
"metadata": {},
"outputs": [
{
......@@ -492,7 +488,7 @@
"{1, 3}"
]
},
"execution_count": 15,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
......@@ -503,7 +499,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 18,
"metadata": {},
"outputs": [
{
......@@ -537,7 +533,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"metadata": {},
"outputs": [
{
......@@ -567,15 +563,15 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"integer remove from the list: 3\n",
"shuffled list: [4, 2, 5, 16, 15, 6, 9, 18, 8, 7, 13, 11, 17, 14, 12, 0, 19, 1, 10]\n"
"integer remove from the list: 12\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 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
"12"
]
},
"execution_count": 4,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
......@@ -668,7 +664,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 22,
"metadata": {},
"outputs": [
{
......@@ -688,7 +684,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 23,
"metadata": {},
"outputs": [
{
......@@ -719,7 +715,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 24,
"metadata": {},
"outputs": [
{
......@@ -738,7 +734,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 25,
"metadata": {},
"outputs": [
{
......@@ -747,7 +743,7 @@
"'value1'"
]
},
"execution_count": 21,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
......@@ -758,7 +754,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 26,
"metadata": {},
"outputs": [
{
......@@ -777,7 +773,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 27,
"metadata": {},
"outputs": [
{
......@@ -786,7 +782,7 @@
"'value1'"
]
},
"execution_count": 23,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
......@@ -815,7 +811,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 28,
"metadata": {},
"outputs": [
{
......@@ -834,7 +830,7 @@
" 'values']"
]
},
"execution_count": 24,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
......@@ -857,7 +853,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 29,
"metadata": {},
"outputs": [
{
......@@ -879,7 +875,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 30,
"metadata": {},
"outputs": [
{
......@@ -900,7 +896,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 31,
"metadata": {},
"outputs": [
{
......@@ -921,21 +917,23 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'key0': 'value0', 'key1': 'value1', 'key2': 'value2'}\n"
"{'key0': 'value0', 'key1': 'value1', 'key2': 'value2'}\n",
"{'key0': 'VALUE0', 'key1': 'VALUE1', 'key2': 'VALUE2'}\n"
]
}
],
"source": [
"# dict comprehension (here for the \"inversion\" of the dictionary)\n",
"# dict comprehension (here to change the case of values)\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 @@
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"text = 'abbbcc'"
......@@ -975,14 +971,14 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"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 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 35,
"metadata": {},
"outputs": [
{
......@@ -1026,20 +1022,20 @@
"output_type": "stream",
"text": [
"len(s) = 7160000, nbkeys 33 base, count, count_count, except, colection.counter\n",
"1 loop, best of 5: 550 ms per loop\n",
"1 loop, best of 5: 495 ms per loop\n",
"10 loops, best of 5: 146 ms per loop\n",
"1 loop, best of 5: 488 ms per loop\n",
"1 loop, best of 5: 265 ms per loop\n",
"1 loop, best of 5: 450 ms per loop\n",
"747 ms ± 51.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"692 ms ± 42.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"286 ms ± 9.76 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"667 ms ± 25.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"355 ms ± 11.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"572 ms ± 9.46 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"with split\n",
"len(s) = 1100000, nbkeys 90 base, count, count_count, except, colection.counter\n",
"10 loops, best of 5: 123 ms per loop\n",
"10 loops, best of 5: 113 ms per loop\n",
"1 loop, best of 5: 992 ms per loop\n",
"10 loops, best of 5: 101 ms per loop\n",
"10 loops, best of 5: 62.3 ms per loop\n",
"1 loop, best of 5: 449 ms per loop\n"
"142 ms ± 2.51 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"147 ms ± 7.07 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"1.71 s ± 184 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"126 ms ± 4.58 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"78.9 ms ± 1.87 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"658 ms ± 65.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
......@@ -1119,10 +1115,8 @@
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": true
},
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
......@@ -1163,7 +1157,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 37,
"metadata": {},
"outputs": [
{
......@@ -1209,7 +1203,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 38,
"metadata": {},
"outputs": [
{
......@@ -1265,7 +1259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.8"
}
},
"nbformat": 4,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment