update module1.ipynb

This commit is contained in:
Yavuz Sava 2025-02-21 18:04:04 +03:00
parent 53d3557be9
commit 5097089952

View File

@ -1,5 +1,158 @@
{
"cells": [],
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Diffing Files\n",
"\n",
"This reading contains the code used in the instructional videos from [**Diffing Files**<svg aria-labelledby=\"cds-react-aria402160580-:rim:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria402160580-:rim:\"><title id=\"cds-react-aria402160580-:rim:-title\">Opens in a new tab</title><path d=\"M4.5 17c-.412 0-.766-.147-1.06-.44A1.445 1.445 0 013 15.5v-11c0-.412.147-.766.44-1.06.294-.293.648-.44 1.06-.44h4.75c.213 0 .39.071.534.214a.72.72 0 01.216.532c0 .21-.072.39-.216.535a.72.72 0 01-.534.219H4.5v11h11v-4.75c0-.213.072-.39.214-.534a.72.72 0 01.532-.216c.21 0 .39.072.535.216a.72.72 0 01.219.534v4.75c0 .412-.147.766-.44 1.06-.294.293-.647.44-1.06.44h-11zm11-11.438L8.583 12.48a.681.681 0 01-.52.219.758.758 0 01-.521-.24.729.729 0 010-1.062L14.438 4.5H12.75a.728.728 0 01-.534-.214.72.72 0 01-.216-.532c0-.21.072-.39.216-.535A.72.72 0 0112.75 3h3.5c.212 0 .39.072.534.216A.726.726 0 0117 3.75v3.5c0 .213-.072.39-.214.534a.72.72 0 01-.532.216.734.734 0 01-.535-.216.72.72 0 01-.219-.534V5.562z\" fill=\"currentColor\" data-darkreader-inline-fill=\"\" style=\"--darkreader-inline-fill: currentColor;\"></path></svg>](https://www.coursera.org/learn/introduction-git-github/lecture/tnlzg/diffing-files) \n",
"\n",
"## Introduction\n",
"\n",
"This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n",
"\n",
"You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n",
"\n",
"```\n",
"cat rearrange1.py \n",
"```\n",
"\n",
"**Code output:**\n",
"\n",
"#!/usr/bin/env python3\n",
"\n",
"import re\n",
"\n",
"def rearrange\\_name(name):\n",
"\n",
"    result = re.search(r\"^(\\[\\\\w .\\]\\*), (\\[\\\\w .\\]\\*)$\", name)\n",
"\n",
"    if result == None:\n",
"\n",
"        return name\n",
"\n",
"    return \"{} {}\".format(result\\[2\\], result\\[1\\])\n",
"\n",
"user@ubuntu:~$ cat rearrange2.py \n",
"\n",
"#!/usr/bin/env python3\n",
"\n",
"import re\n",
"\n",
"def rearrange\\_name(name):\n",
"\n",
"    result = re.search(r\"^(\\[\\\\w .-\\]\\*), (\\[\\\\w .-\\]\\*)$\", name)\n",
"\n",
"    if result == None:\n",
"\n",
"        return name\n",
"\n",
"    return \"{} {}\".format(result\\[2\\], result\\[1\\])\n",
"\n",
"1\n",
"\n",
"```\n",
"cat rearrange2.py \n",
"```\n",
"\n",
"**Code output:**\n",
"\n",
"#!/usr/bin/env python3\n",
"\n",
"import re\n",
"\n",
"def rearrange\\_name(name):\n",
"\n",
"    result = re.search(r\"^(\\[\\\\w .-\\]\\*), (\\[\\\\w .-\\]\\*)$\", name)\n",
"\n",
"    if result == None:\n",
"\n",
"        return name\n",
"\n",
"    return \"{} {}\".format(result\\[2\\], result\\[1\\])\n",
"\n",
"```\n",
"diff rearrange1.py rearrange2.py \n",
"```\n",
"\n",
"**Code output:**\n",
"\n",
"6c6\n",
"\n",
"<     result = re.search(r\"^(\\[\\\\w .\\]\\*), (\\[\\\\w .\\]\\*)$\", name)\n",
"\n",
"\\---\n",
"\n",
"\\>     result = re.search(r\"^(\\[\\\\w .-\\]\\*), (\\[\\\\w .-\\]\\*)$\", name)\n",
"\n",
"\n",
"```\n",
"diff validations1.py validations2.py \n",
"```\n",
"\n",
"**Code output:**\n",
"\n",
"5c5,6\n",
"\n",
"< assert (type(username) == str), \"username must be a string\"\n",
"\n",
"\\--\n",
"\n",
"\\> if type(username != str: \n",
"\n",
"\\>     raise TypeError(\"username must be a string\"\n",
"\n",
"11a13,15\n",
"\n",
"\\>     return False\n",
"\n",
"\\> # Usernames can't begin with a number\n",
"\n",
"\\> if username\\[0\\].isnumeric():\n",
"\n",
"```\n",
"diff \\-u validations1.py validations2.py \n",
"```\n",
"\n",
"**Code output:**\n",
"\n",
"\\--- validations1.py 2019-06-06 14:28:49.639209499 +0200\n",
"\n",
"+++ validations2.py 2019-06-06 14:30:48.019360890 +0200\n",
"\n",
"@@ -2,7 +2,8 @@\n",
"\n",
" def validate\\_user(username, minlen):\n",
"\n",
"\\-    assert type(username) == str, \"username must be a string\"\n",
"\n",
"+    if type(username) != str:\n",
"\n",
"+        raise TypeError(\"username must be a string\")\n",
"\n",
"     if minlen < 1:\n",
"\n",
"         raise ValueError(\"minlen must be at least 1\")\n",
"\n",
"@@ -10,5 +11,8 @@\n",
"\n",
"         return False\n",
"\n",
"     if not username.isalnum():\n",
"\n",
"         return False\n",
"\n",
"+    # Usernames can't begin with a number\n",
"\n",
"+    if username\\[0\\].isnumeric():\n",
"\n",
"+        return False\n",
"\n",
"     return True"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",