This commit is contained in:
James Turk 2024-09-30 00:42:17 -05:00
parent 23a364774e
commit bded23163b
4 changed files with 175 additions and 119 deletions

View File

@ -305,7 +305,9 @@
} }
], ],
"source": [ "source": [
"print(\"Hi\", 2 * 3 * 47 * 181, \"!\") # the advantage is that I can mix code in with my notes" "print(\n",
" \"Hi\", 2 * 3 * 47 * 181, \"!\"\n",
") # the advantage is that I can mix code in with my notes"
] ]
}, },
{ {
@ -547,7 +549,7 @@
} }
], ],
"source": [ "source": [
"(.1 + .2) == .3" "(0.1 + 0.2) == 0.3"
] ]
}, },
{ {
@ -570,7 +572,7 @@
} }
], ],
"source": [ "source": [
".1 + .2" "0.1 + 0.2"
] ]
}, },
{ {
@ -602,10 +604,10 @@
} }
], ],
"source": [ "source": [
"print(.1 + .2 == .3)\n", "print(0.1 + 0.2 == 0.3)\n",
"\n", "\n",
"episilon = 0.000000001\n", "episilon = 0.000000001\n",
"abs((.1 + .2) - .3) < episilon\n", "abs((0.1 + 0.2) - 0.3) < episilon\n",
"\n", "\n",
"# bank_account_hundredths_of_cent = 1000000000" "# bank_account_hundredths_of_cent = 1000000000"
] ]
@ -818,10 +820,12 @@
"# we'll discuss how to write functions/etc. soon\n", "# we'll discuss how to write functions/etc. soon\n",
"import time\n", "import time\n",
"\n", "\n",
"\n",
"def short_func():\n", "def short_func():\n",
" print(\"short_func\")\n", " print(\"short_func\")\n",
" return False\n", " return False\n",
"\n", "\n",
"\n",
"def long_func():\n", "def long_func():\n",
" print(\"long_func\")\n", " print(\"long_func\")\n",
" time.sleep(1)\n", " time.sleep(1)\n",
@ -1351,7 +1355,7 @@
"\n", "\n",
"one_item_tuple = (1 + 2,) # why is the comma necessary?\n", "one_item_tuple = (1 + 2,) # why is the comma necessary?\n",
"\n", "\n",
"bad_tuple = (1+492)\n", "bad_tuple = 1 + 492\n",
"\n", "\n",
"print(bad_tuple) # why is this not a tuple?" "print(bad_tuple) # why is this not a tuple?"
] ]
@ -1602,7 +1606,7 @@
"# concatenation & repetition demo\n", "# concatenation & repetition demo\n",
"s2 = \"*\" * 5\n", "s2 = \"*\" * 5\n",
"t2 = (True, False) * 3\n", "t2 = (True, False) * 3\n",
"l2 = [\"a\", \"b\", \"c\"] * 4\n" "l2 = [\"a\", \"b\", \"c\"] * 4"
] ]
}, },
{ {
@ -1640,7 +1644,18 @@
} }
], ],
"source": [ "source": [
"cities = [\"Tokyo\", \"Delhi\", \"Shanghai\", \"São Paulo\", \"Mexico City\", \"Cairo\", \"Mumbai\", \"Beijing\", \"Dhaka\", \"Osaka\"]\n", "cities = [\n",
" \"Tokyo\",\n",
" \"Delhi\",\n",
" \"Shanghai\",\n",
" \"São Paulo\",\n",
" \"Mexico City\",\n",
" \"Cairo\",\n",
" \"Mumbai\",\n",
" \"Beijing\",\n",
" \"Dhaka\",\n",
" \"Osaka\",\n",
"]\n",
"text = \"Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal\"\n", "text = \"Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal\"\n",
"ids = (123, 555, 81, 110, 44, 12, 16)\n", "ids = (123, 555, 81, 110, 44, 12, 16)\n",
"ids[0]" "ids[0]"
@ -1996,14 +2011,14 @@
"x = 49490\n", "x = 49490\n",
"\n", "\n",
"if x < 0:\n", "if x < 0:\n",
" print('negative')\n", " print(\"negative\")\n",
" print(\"second line\")\n", " print(\"second line\")\n",
"elif x == 0:\n", "elif x == 0:\n",
" print('zero')\n", " print(\"zero\")\n",
"elif x == 4:\n", "elif x == 4:\n",
" print(\"four\")\n", " print(\"four\")\n",
"else:\n", "else:\n",
" print('positive')" " print(\"positive\")"
] ]
}, },
{ {
@ -2123,7 +2138,7 @@
" continue\n", " continue\n",
" print(city)\n", " print(city)\n",
"\n", "\n",
"seconds_left = 7\n" "seconds_left = 7"
] ]
}, },
{ {
@ -2197,8 +2212,7 @@
" print(\"found a comma!\")\n", " print(\"found a comma!\")\n",
" break\n", " break\n",
"else:\n", "else:\n",
" print('no comma found!')\n", " print(\"no comma found!\")"
" "
] ]
}, },
{ {
@ -2469,10 +2483,13 @@
"# I've broken this function into multiple lines, which is allowed\n", "# I've broken this function into multiple lines, which is allowed\n",
"# due to the parentheses.\n", "# due to the parentheses.\n",
"\n", "\n",
"\n",
"def find_value(\n", "def find_value(\n",
" a_list: list[int], # this parameter is a list of integers\n", " a_list: list[int], # this parameter is a list of integers\n",
" num: int # this parameter is a single integer\n", " num: int, # this parameter is a single integer\n",
") -> int | None: # this annotation \"-> int | None\" indicates return type can be int or None\n", ") -> (\n",
" int | None\n",
"): # this annotation \"-> int | None\" indicates return type can be int or None\n",
" pass" " pass"
] ]
}, },

View File

@ -549,7 +549,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"record1[\"name\"] = \"Anne\"\n" "record1[\"name\"] = \"Anne\""
] ]
}, },
{ {
@ -941,7 +941,7 @@
"print(order)\n", "print(order)\n",
"key = \"fish\"\n", "key = \"fish\"\n",
"\n", "\n",
"#print(d.get(key), key)\n" "# print(d.get(key), key)"
] ]
}, },
{ {
@ -1071,7 +1071,7 @@
} }
], ],
"source": [ "source": [
"dishes = {'eggs':2,'sausage':1,'bacon':1,'spam':500}\n", "dishes = {\"eggs\": 2, \"sausage\": 1, \"bacon\": 1, \"spam\": 500}\n",
"\n", "\n",
"# Keys is a view object of the keys from the dishes dictionary\n", "# Keys is a view object of the keys from the dishes dictionary\n",
"keys = dishes.keys()\n", "keys = dishes.keys()\n",
@ -1107,7 +1107,7 @@
"# View objects are dynamic and reflect dictionary changes\n", "# View objects are dynamic and reflect dictionary changes\n",
"\n", "\n",
"# Lets delete the 'eggs' entry\n", "# Lets delete the 'eggs' entry\n",
"del dishes['eggs']\n", "del dishes[\"eggs\"]\n",
"\n", "\n",
"# Notice the both the views have removed key and its value\n", "# Notice the both the views have removed key and its value\n",
"print(keys)\n", "print(keys)\n",
@ -1136,7 +1136,7 @@
"menu = {\n", "menu = {\n",
" \"Breakfast\": {\"Eggs\": 2.19, \"Toast\": 0.99, \"Orange Juice\": 1.99},\n", " \"Breakfast\": {\"Eggs\": 2.19, \"Toast\": 0.99, \"Orange Juice\": 1.99},\n",
" \"Lunch\": {\"BLT\": 3.99, \"Chicken\": 5.99, \"Salad\": 4.50},\n", " \"Lunch\": {\"BLT\": 3.99, \"Chicken\": 5.99, \"Salad\": 4.50},\n",
" \"Dinner\": {\"Cheeseburger\": 9.99, \"Salad\": 7.50, \"Special\": 8.49}\n", " \"Dinner\": {\"Cheeseburger\": 9.99, \"Salad\": 7.50, \"Special\": 8.49},\n",
"}\n", "}\n",
"\n", "\n",
"print(menu[\"Lunch\"])\n", "print(menu[\"Lunch\"])\n",
@ -1185,6 +1185,7 @@
" d.pop(item)\n", " d.pop(item)\n",
" # ...\n", " # ...\n",
"\n", "\n",
"\n",
"scores = {\"A\": 100, \"B\": 20, \"C\": 48}\n", "scores = {\"A\": 100, \"B\": 20, \"C\": 48}\n",
"something(scores)\n", "something(scores)\n",
"print(scores)" "print(scores)"
@ -1387,7 +1388,7 @@
"source": [ "source": [
"# The following creates a set of single strings 'a','b','c','d','e'\n", "# The following creates a set of single strings 'a','b','c','d','e'\n",
"# and another set of single strings 'b','d','x','y','z'\n", "# and another set of single strings 'b','d','x','y','z'\n",
"A = set('abcde')\n", "A = set(\"abcde\")\n",
"B = set([\"b\", \"d\", \"x\", \"y\", \"z\"])\n", "B = set([\"b\", \"d\", \"x\", \"y\", \"z\"])\n",
"\n", "\n",
"print(\"A = \", A)\n", "print(\"A = \", A)\n",
@ -1409,7 +1410,7 @@
"# Union Operation\n", "# Union Operation\n",
"new_set = A | B\n", "new_set = A | B\n",
"print(new_set)\n", "print(new_set)\n",
"print('---')\n", "print(\"---\")\n",
"new_set = A.union(B) # Same operation as above but using method\n", "new_set = A.union(B) # Same operation as above but using method\n",
"print(new_set)" "print(new_set)"
] ]
@ -1447,7 +1448,7 @@
"# Intersection Operation\n", "# Intersection Operation\n",
"new_set = A & B\n", "new_set = A & B\n",
"print(new_set)\n", "print(new_set)\n",
"print('---')\n", "print(\"---\")\n",
"new_set = A.intersection(B) # same operation as above but using method\n", "new_set = A.intersection(B) # same operation as above but using method\n",
"print(new_set)" "print(new_set)"
] ]
@ -1466,7 +1467,7 @@
"# Symmetric Difference Operation\n", "# Symmetric Difference Operation\n",
"new_set = A ^ B\n", "new_set = A ^ B\n",
"print(new_set)\n", "print(new_set)\n",
"print('---')\n", "print(\"---\")\n",
"new_set = A.symmetric_difference(B) # same operation as above but using method\n", "new_set = A.symmetric_difference(B) # same operation as above but using method\n",
"print(new_set)" "print(new_set)"
] ]
@ -1585,8 +1586,16 @@
"print(s)\n", "print(s)\n",
"\n", "\n",
"\n", "\n",
"\n", "\"Honda Civic\" in [\n",
"\"Honda Civic\" in [\"Honda Civic\", \"Ford Focus\", \"Honda Civic\", \"Honda Civic\", \"Honda Civic\", \"Honda Civic\", \"Honda Civic\", \"Escalade\"]" " \"Honda Civic\",\n",
" \"Ford Focus\",\n",
" \"Honda Civic\",\n",
" \"Honda Civic\",\n",
" \"Honda Civic\",\n",
" \"Honda Civic\",\n",
" \"Honda Civic\",\n",
" \"Escalade\",\n",
"]"
] ]
}, },
{ {
@ -1642,7 +1651,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"\n",
"students = [\n", "students = [\n",
" {\"name\": \"adam\", \"num\": 123},\n", " {\"name\": \"adam\", \"num\": 123},\n",
" {\"name\": \"quynh\", \"num\": 456},\n", " {\"name\": \"quynh\", \"num\": 456},\n",
@ -2292,10 +2300,10 @@
} }
], ],
"source": [ "source": [
"fruit1 = ('Apples', 4)\n", "fruit1 = (\"Apples\", 4)\n",
"fruit2 = ('Apples', 4)\n", "fruit2 = (\"Apples\", 4)\n",
"fruit3 = fruit2\n", "fruit3 = fruit2\n",
"print(f'Fruit1 id = {id(fruit1)} \\n Fruit2 id = {id(fruit2)}')\n", "print(f\"Fruit1 id = {id(fruit1)} \\n Fruit2 id = {id(fruit2)}\")\n",
"print(f\"Fruit3 id= {id(fruit3)}\")" "print(f\"Fruit3 id= {id(fruit3)}\")"
] ]
}, },
@ -2485,8 +2493,8 @@
], ],
"source": [ "source": [
"# CPython does the same for short strings\n", "# CPython does the same for short strings\n",
"str1 = 'MPCS' * 100\n", "str1 = \"MPCS\" * 100\n",
"str2 = 'MPCS' * 100\n", "str2 = \"MPCS\" * 100\n",
"print(id(str1), id(str2))\n", "print(id(str1), id(str2))\n",
"str1 is str2" "str1 is str2"
] ]
@ -2558,7 +2566,7 @@
"\n", "\n",
"# print(x, y)\n", "# print(x, y)\n",
"x[0].append(5)\n", "x[0].append(5)\n",
"print(x, \"\\n\", y)\n" "print(x, \"\\n\", y)"
] ]
}, },
{ {
@ -2582,6 +2590,7 @@
"source": [ "source": [
"# deep copy\n", "# deep copy\n",
"import copy\n", "import copy\n",
"\n",
"# copy.copy(obj) --> same as obj.copy()\n", "# copy.copy(obj) --> same as obj.copy()\n",
"z = copy.deepcopy(x)\n", "z = copy.deepcopy(x)\n",
"print(\"x[0] is z[0]\", x[0] is z[0])" "print(\"x[0] is z[0]\", x[0] is z[0])"

View File

@ -6,4 +6,5 @@ readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = [ dependencies = [
"jupyter>=1.1.1", "jupyter>=1.1.1",
"ruff>=0.6.8",
] ]

31
uv.lock generated
View File

@ -7,10 +7,14 @@ version = "0.1.0"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "jupyter" }, { name = "jupyter" },
{ name = "ruff" },
] ]
[package.metadata] [package.metadata]
requires-dist = [{ name = "jupyter", specifier = ">=1.1.1" }] requires-dist = [
{ name = "jupyter", specifier = ">=1.1.1" },
{ name = "ruff", specifier = ">=0.6.8" },
]
[[package]] [[package]]
name = "anyio" name = "anyio"
@ -1335,6 +1339,31 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d2/ea/6f121d1802f3adae1981aea4209ea66f9d3c7f2f6d6b85ef4f13a61d17ef/rpds_py-0.20.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:bb273176be34a746bdac0b0d7e4e2c467323d13640b736c4c477881a3220a989", size = 213529 }, { url = "https://files.pythonhosted.org/packages/d2/ea/6f121d1802f3adae1981aea4209ea66f9d3c7f2f6d6b85ef4f13a61d17ef/rpds_py-0.20.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:bb273176be34a746bdac0b0d7e4e2c467323d13640b736c4c477881a3220a989", size = 213529 },
] ]
[[package]]
name = "ruff"
version = "0.6.8"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/74/f9/4ce3e765a72ab8fe0f80f48508ea38b4196daab3da14d803c21349b2d367/ruff-0.6.8.tar.gz", hash = "sha256:a5bf44b1aa0adaf6d9d20f86162b34f7c593bfedabc51239953e446aefc8ce18", size = 3084543 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/db/07/42ee57e8b76ca585297a663a552b4f6d6a99372ca47fdc2276ef72cc0f2f/ruff-0.6.8-py3-none-linux_armv6l.whl", hash = "sha256:77944bca110ff0a43b768f05a529fecd0706aac7bcce36d7f1eeb4cbfca5f0f2", size = 10404327 },
{ url = "https://files.pythonhosted.org/packages/eb/51/d42571ff8156d65086acb72d39aa64cb24181db53b497d0ed6293f43f07a/ruff-0.6.8-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:27b87e1801e786cd6ede4ada3faa5e254ce774de835e6723fd94551464c56b8c", size = 10018797 },
{ url = "https://files.pythonhosted.org/packages/c1/d7/fa5514a60b03976af972b67fe345deb0335dc96b9f9a9fa4df9890472427/ruff-0.6.8-py3-none-macosx_11_0_arm64.whl", hash = "sha256:cd48f945da2a6334f1793d7f701725a76ba93bf3d73c36f6b21fb04d5338dcf5", size = 9691303 },
{ url = "https://files.pythonhosted.org/packages/d6/c4/d812a74976927e51d0782a47539069657ac78535779bfa4d061c4fc8d89d/ruff-0.6.8-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:677e03c00f37c66cea033274295a983c7c546edea5043d0c798833adf4cf4c6f", size = 10719452 },
{ url = "https://files.pythonhosted.org/packages/ec/b6/aa700c4ae6db9b3ee660e23f3c7db596e2b16a3034b797704fba33ddbc96/ruff-0.6.8-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9f1476236b3eacfacfc0f66aa9e6cd39f2a624cb73ea99189556015f27c0bdeb", size = 10161353 },
{ url = "https://files.pythonhosted.org/packages/ea/39/0b10075ffcd52ff3a581b9b69eac53579deb230aad300ce8f9d0b58e77bc/ruff-0.6.8-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6f5a2f17c7d32991169195d52a04c95b256378bbf0de8cb98478351eb70d526f", size = 10980630 },
{ url = "https://files.pythonhosted.org/packages/c1/af/9eb9efc98334f62652e2f9318f137b2667187851911fac3b395365a83708/ruff-0.6.8-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:5fd0d4b7b1457c49e435ee1e437900ced9b35cb8dc5178921dfb7d98d65a08d0", size = 11768996 },
{ url = "https://files.pythonhosted.org/packages/e0/59/8b1369cf7878358952b1c0a1559b4d6b5c824c003d09b0db26d26c9d094f/ruff-0.6.8-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f8034b19b993e9601f2ddf2c517451e17a6ab5cdb1c13fdff50c1442a7171d87", size = 11317469 },
{ url = "https://files.pythonhosted.org/packages/b9/6d/e252e9b11bbca4114c386ee41ad559d0dac13246201d77ea1223c6fea17f/ruff-0.6.8-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6cfb227b932ba8ef6e56c9f875d987973cd5e35bc5d05f5abf045af78ad8e098", size = 12467185 },
{ url = "https://files.pythonhosted.org/packages/48/44/7caa223af7d4ea0f0b2bd34acca65a7694a58317714675a2478815ab3f45/ruff-0.6.8-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6ef0411eccfc3909269fed47c61ffebdcb84a04504bafa6b6df9b85c27e813b0", size = 10887766 },
{ url = "https://files.pythonhosted.org/packages/81/ed/394aff3a785f171869158b9d5be61eec9ffb823c3ad5d2bdf2e5f13cb029/ruff-0.6.8-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:007dee844738c3d2e6c24ab5bc7d43c99ba3e1943bd2d95d598582e9c1b27750", size = 10711609 },
{ url = "https://files.pythonhosted.org/packages/47/31/f31d04c842e54699eab7e3b864538fea26e6c94b71806cd10aa49f13e1c1/ruff-0.6.8-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:ce60058d3cdd8490e5e5471ef086b3f1e90ab872b548814e35930e21d848c9ce", size = 10237621 },
{ url = "https://files.pythonhosted.org/packages/20/95/a764e84acf11d425f2f23b8b78b4fd715e9c20be4aac157c6414ca859a67/ruff-0.6.8-py3-none-musllinux_1_2_i686.whl", hash = "sha256:1085c455d1b3fdb8021ad534379c60353b81ba079712bce7a900e834859182fa", size = 10558329 },
{ url = "https://files.pythonhosted.org/packages/2a/76/d4e38846ac9f6dd62dce858a54583911361b5339dcf8f84419241efac93a/ruff-0.6.8-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:70edf6a93b19481affd287d696d9e311388d808671bc209fb8907b46a8c3af44", size = 10954102 },
{ url = "https://files.pythonhosted.org/packages/e7/36/f18c678da6c69f8d022480f3e8ddce6e4a52e07602c1d212056fbd234f8f/ruff-0.6.8-py3-none-win32.whl", hash = "sha256:792213f7be25316f9b46b854df80a77e0da87ec66691e8f012f887b4a671ab5a", size = 8511090 },
{ url = "https://files.pythonhosted.org/packages/4c/c4/0ca7d8ffa358b109db7d7d045a1a076fd8e5d9cbeae022242d3c060931da/ruff-0.6.8-py3-none-win_amd64.whl", hash = "sha256:ec0517dc0f37cad14a5319ba7bba6e7e339d03fbf967a6d69b0907d61be7a263", size = 9350079 },
{ url = "https://files.pythonhosted.org/packages/d9/bd/a8b0c64945a92eaeeb8d0283f27a726a776a1c9d12734d990c5fc7a1278c/ruff-0.6.8-py3-none-win_arm64.whl", hash = "sha256:8d3bb2e3fbb9875172119021a13eed38849e762499e3cfde9588e4b4d70968dc", size = 8669595 },
]
[[package]] [[package]]
name = "send2trash" name = "send2trash"
version = "1.8.3" version = "1.8.3"