update
This commit is contained in:
parent
dde17611c6
commit
5caeef0bca
@ -351,20 +351,9 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"True\n",
|
||||
"False\n",
|
||||
"True\n",
|
||||
"False\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"def check_zip_code (text):\n",
|
||||
@ -402,12 +391,80 @@
|
||||
"\"{} {}\".format(result[2], result[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Groups"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Lovelace Ada\n",
|
||||
"Ada Lovelace\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"def rearrange_name(name):\n",
|
||||
" result = re.search(r\"^(\\w*), (\\w*)$\", name)\n",
|
||||
" if result is None:\n",
|
||||
" return name\n",
|
||||
" return \"{} {}\".format(result[1], result[2])\n",
|
||||
"def rearrange_surname(name):\n",
|
||||
" result = re.search(r\"^(\\w*), (\\w*)$\", name)\n",
|
||||
" if result is None:\n",
|
||||
" return name\n",
|
||||
" return \"{} {}\".format(result[2], result[1])\n",
|
||||
"print(rearrange_name(\"Lovelace, Ada\"))\n",
|
||||
"print(rearrange_surname(\"Lovelace, Ada\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"# Fix the regular expression used in the rearrange_name function so that it can match middle names, middle initials, as well as double surnames.\n",
|
||||
"import re\n",
|
||||
"def rearrange_name(name):\n",
|
||||
"# result = re.search(r\"^(\\w*), (\\w*)$\", name) # from this to:\n",
|
||||
" result = re.search(r\"^(\\w.*\\w*), (\\w.*\\w*)$\", name)\n",
|
||||
" if result == None:\n",
|
||||
" return name\n",
|
||||
" return \"{} {}\".format(result[2], result[1])\n",
|
||||
"\n",
|
||||
"name=rearrange_name(\"Kennedy, John F.\")\n",
|
||||
"print(name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Repetition Qualifiers"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"print(re.search(r\"[a-zA-Z]{5}\", \"a ghost\"))\n",
|
||||
"print(re.search(r\"[a-zA-Z]{5}\", \"a scary ghost appeared\"))\n",
|
||||
"print(re.findall(r\"[a-zA-Z]{5}\", \"a scary ghost appeared\"))"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
Reference in New Issue
Block a user