Commit 2f31e2af authored by Franck Thollard's avatar Franck Thollard
Browse files

Merge branch 'master' of gricad-gitlab.univ-grenoble-alpes.fr:python-uga/py-training-2017

parents 81c9fcd8 828ef83c
......@@ -1051,7 +1051,8 @@
"- Extract the first field (e.g. using `find` method and slicing)\n",
"- Extract the last field (e.g. using `rfind` method and slicing)\n",
"- Check for empty field (e.g. `find` \";;\" pattern)\n",
"- Remove empty field (e.g. using replace method)"
"- Remove empty field (e.g. using replace method)\n",
"- BONUS : Extract the second field (tip :`find` can take an argument that tells where to start the search)"
]
},
{
......@@ -1067,7 +1068,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 12,
"metadata": {},
"outputs": [
{
......@@ -1076,6 +1077,7 @@
"text": [
"--wind;temperature;;pressure--\n",
"wind\n",
"temperature\n",
"pressure\n",
"16\n",
"wind;temperature;pressure\n"
......@@ -1091,10 +1093,14 @@
"idx = s.find(\";\")\n",
"s0 = s[0:idx]\n",
"print(s0)\n",
"# extract the last field\n",
"idx = s.rfind(\";\")\n",
"s1 = s[idx+1:]\n",
"# extract the second field\n",
"idx1 = s.find(\";\", idx+1) # start the search after the first \";\"\n",
"s1 = s[idx+1:idx1]\n",
"print(s1)\n",
"# extract the last field\n",
"idx2 = s.rfind(\";\")\n",
"s2 = s[idx2+1:]\n",
"print(s2)\n",
"idx_first_empty_field = s.find(\";;\")\n",
"print(idx_first_empty_field)\n",
"# remove empty field\n",
......
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