Skip to content

Commit de98cbd

Browse files
committed
move data and fix typos
1 parent c6e7f0c commit de98cbd

File tree

8 files changed

+480
-110
lines changed

8 files changed

+480
-110
lines changed

notebooks/ABCOperatorOverloading.ipynb

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,14 @@
300300
"## Creating an abstract base class (ABC)\n",
301301
"\n",
302302
"- define a media player as an *abstraction*\n",
303-
"- each unique kind of media file format can provide a *concrete* implementation of the abstraction\n"
303+
"- each unique kind of media file format can provide a *concrete* implementation of the abstraction\n",
304+
"- use `pass` or `...` keywords to complete the function definition\n",
305+
"- doc string also syntactically completes the function definition"
304306
]
305307
},
306308
{
307309
"cell_type": "code",
308-
"execution_count": 2,
310+
"execution_count": 5,
309311
"id": "5e57a147",
310312
"metadata": {},
311313
"outputs": [],
@@ -320,12 +322,12 @@
320322
" @property\n",
321323
" @abc.abstractmethod\n",
322324
" def ext(self) -> str:\n",
323-
" ... # placeholder"
325+
" pass # placeholder"
324326
]
325327
},
326328
{
327329
"cell_type": "code",
328-
"execution_count": 3,
330+
"execution_count": 2,
329331
"id": "294121e7",
330332
"metadata": {},
331333
"outputs": [
@@ -335,7 +337,7 @@
335337
"frozenset({'ext', 'play'})"
336338
]
337339
},
338-
"execution_count": 3,
340+
"execution_count": 2,
339341
"metadata": {},
340342
"output_type": "execute_result"
341343
}
@@ -347,7 +349,7 @@
347349
},
348350
{
349351
"cell_type": "code",
350-
"execution_count": 4,
352+
"execution_count": 3,
351353
"id": "1441f4f5",
352354
"metadata": {},
353355
"outputs": [],
@@ -360,7 +362,7 @@
360362
},
361363
{
362364
"cell_type": "code",
363-
"execution_count": 5,
365+
"execution_count": 4,
364366
"id": "e48e0a24",
365367
"metadata": {},
366368
"outputs": [
@@ -371,7 +373,7 @@
371373
"traceback": [
372374
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
373375
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
374-
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m wav \u001b[38;5;241m=\u001b[39m \u001b[43mWav\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
376+
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m wav \u001b[38;5;241m=\u001b[39m \u001b[43mWav\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
375377
"\u001b[0;31mTypeError\u001b[0m: Can't instantiate abstract class Wav without an implementation for abstract methods 'ext', 'play'"
376378
]
377379
}
@@ -2289,7 +2291,7 @@
22892291
},
22902292
{
22912293
"cell_type": "code",
2292-
"execution_count": 26,
2294+
"execution_count": 6,
22932295
"id": "705402ce",
22942296
"metadata": {},
22952297
"outputs": [],
@@ -2299,7 +2301,7 @@
22992301
},
23002302
{
23012303
"cell_type": "code",
2302-
"execution_count": 27,
2304+
"execution_count": 7,
23032305
"id": "16c60228",
23042306
"metadata": {},
23052307
"outputs": [],
@@ -2309,7 +2311,7 @@
23092311
},
23102312
{
23112313
"cell_type": "code",
2312-
"execution_count": 28,
2314+
"execution_count": 8,
23132315
"id": "b40b289e",
23142316
"metadata": {},
23152317
"outputs": [
@@ -2319,7 +2321,7 @@
23192321
"True"
23202322
]
23212323
},
2322-
"execution_count": 28,
2324+
"execution_count": 8,
23232325
"metadata": {},
23242326
"output_type": "execute_result"
23252327
}
@@ -2330,7 +2332,7 @@
23302332
},
23312333
{
23322334
"cell_type": "code",
2333-
"execution_count": 13,
2335+
"execution_count": 9,
23342336
"id": "79cdfb0c",
23352337
"metadata": {},
23362338
"outputs": [],
@@ -2350,7 +2352,7 @@
23502352
},
23512353
{
23522354
"cell_type": "code",
2353-
"execution_count": 14,
2355+
"execution_count": 11,
23542356
"id": "5ad8ae13",
23552357
"metadata": {},
23562358
"outputs": [],
@@ -2410,7 +2412,7 @@
24102412
},
24112413
{
24122414
"cell_type": "code",
2413-
"execution_count": 15,
2415+
"execution_count": 12,
24142416
"id": "d792e308",
24152417
"metadata": {},
24162418
"outputs": [],
@@ -2420,7 +2422,7 @@
24202422
},
24212423
{
24222424
"cell_type": "code",
2423-
"execution_count": 16,
2425+
"execution_count": 13,
24242426
"id": "f0856d8e",
24252427
"metadata": {},
24262428
"outputs": [
@@ -2430,7 +2432,7 @@
24302432
"True"
24312433
]
24322434
},
2433-
"execution_count": 16,
2435+
"execution_count": 13,
24342436
"metadata": {},
24352437
"output_type": "execute_result"
24362438
}
@@ -2441,7 +2443,7 @@
24412443
},
24422444
{
24432445
"cell_type": "code",
2444-
"execution_count": 17,
2446+
"execution_count": 14,
24452447
"id": "dc87e61e",
24462448
"metadata": {},
24472449
"outputs": [
@@ -2451,7 +2453,7 @@
24512453
"False"
24522454
]
24532455
},
2454-
"execution_count": 17,
2456+
"execution_count": 14,
24552457
"metadata": {},
24562458
"output_type": "execute_result"
24572459
}
@@ -2462,7 +2464,7 @@
24622464
},
24632465
{
24642466
"cell_type": "code",
2465-
"execution_count": 18,
2467+
"execution_count": 15,
24662468
"id": "10fe3839",
24672469
"metadata": {},
24682470
"outputs": [
@@ -2472,7 +2474,7 @@
24722474
"26"
24732475
]
24742476
},
2475-
"execution_count": 18,
2477+
"execution_count": 15,
24762478
"metadata": {},
24772479
"output_type": "execute_result"
24782480
}
@@ -2483,7 +2485,7 @@
24832485
},
24842486
{
24852487
"cell_type": "code",
2486-
"execution_count": 19,
2488+
"execution_count": 16,
24872489
"id": "dd8831c1",
24882490
"metadata": {},
24892491
"outputs": [
@@ -2494,8 +2496,8 @@
24942496
"traceback": [
24952497
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
24962498
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
2497-
"Cell \u001b[0;32mIn[19], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mlook\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mm\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
2498-
"Cell \u001b[0;32mIn[14], line 50\u001b[0m, in \u001b[0;36mLookup.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkey_list[index]:\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue_list[index]\n\u001b[0;32m---> 50\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n",
2499+
"Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mlook\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mm\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
2500+
"Cell \u001b[0;32mIn[11], line 50\u001b[0m, in \u001b[0;36mLookup.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkey_list[index]:\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue_list[index]\n\u001b[0;32m---> 50\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n",
24992501
"\u001b[0;31mKeyError\u001b[0m: 'm'"
25002502
]
25012503
}
@@ -2506,7 +2508,7 @@
25062508
},
25072509
{
25082510
"cell_type": "code",
2509-
"execution_count": 20,
2511+
"execution_count": 17,
25102512
"id": "bb8c7c86",
25112513
"metadata": {},
25122514
"outputs": [
@@ -2528,7 +2530,7 @@
25282530
},
25292531
{
25302532
"cell_type": "code",
2531-
"execution_count": 22,
2533+
"execution_count": 18,
25322534
"id": "781ea19a",
25332535
"metadata": {},
25342536
"outputs": [],
@@ -2544,7 +2546,7 @@
25442546
},
25452547
{
25462548
"cell_type": "code",
2547-
"execution_count": 23,
2549+
"execution_count": 19,
25482550
"id": "53aa2e9f",
25492551
"metadata": {},
25502552
"outputs": [
@@ -2554,7 +2556,7 @@
25542556
"'Apple'"
25552557
]
25562558
},
2557-
"execution_count": 23,
2559+
"execution_count": 19,
25582560
"metadata": {},
25592561
"output_type": "execute_result"
25602562
}
@@ -2565,7 +2567,7 @@
25652567
},
25662568
{
25672569
"cell_type": "code",
2568-
"execution_count": 24,
2570+
"execution_count": 20,
25692571
"id": "7debae1a",
25702572
"metadata": {},
25712573
"outputs": [
@@ -2576,8 +2578,8 @@
25762578
"traceback": [
25772579
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
25782580
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
2579-
"Cell \u001b[0;32mIn[24], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m10\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
2580-
"Cell \u001b[0;32mIn[14], line 50\u001b[0m, in \u001b[0;36mLookup.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkey_list[index]:\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue_list[index]\n\u001b[0;32m---> 50\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n",
2581+
"Cell \u001b[0;32mIn[20], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m10\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
2582+
"Cell \u001b[0;32mIn[11], line 50\u001b[0m, in \u001b[0;36mLookup.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkey_list[index]:\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue_list[index]\n\u001b[0;32m---> 50\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n",
25812583
"\u001b[0;31mKeyError\u001b[0m: '10'"
25822584
]
25832585
}
@@ -2586,6 +2588,29 @@
25862588
"x['10']"
25872589
]
25882590
},
2591+
{
2592+
"cell_type": "code",
2593+
"execution_count": 21,
2594+
"id": "46bf015b-f43b-4e11-8095-24e45ae193fd",
2595+
"metadata": {},
2596+
"outputs": [
2597+
{
2598+
"ename": "TypeError",
2599+
"evalue": "'Lookup' object does not support item assignment",
2600+
"output_type": "error",
2601+
"traceback": [
2602+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
2603+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
2604+
"Cell \u001b[0;32mIn[21], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m10\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTen\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
2605+
"\u001b[0;31mTypeError\u001b[0m: 'Lookup' object does not support item assignment"
2606+
]
2607+
}
2608+
],
2609+
"source": [
2610+
"# Immutable dictionary! __setitem__ is not implemented!\n",
2611+
"x['10'] = 'Ten'"
2612+
]
2613+
},
25892614
{
25902615
"cell_type": "markdown",
25912616
"id": "f6b36878",
@@ -3069,7 +3094,8 @@
30693094
" return self[i]\n",
30703095
"```\n",
30713096
" \n",
3072-
"2. Create a new data structure called CD inherited from MutableSequence.\n",
3097+
"2. Solve Kattis CD problem - https://open.kattis.com/problems/cd using ABC and OOD\n",
3098+
" - Create a new data structure called CD inherited from MutableSequence.\n",
30733099
" - CD must have `common()` interface method to find the intersection between other CD object\n",
30743100
" - `__and__()` method overloads `&` intersection operator\n",
30753101
" - e.g., jack & jill\n",

0 commit comments

Comments
 (0)