Skip to content

Commit 03c4288

Browse files
committed
chore: ch2 note - fluent interface & sort
1 parent 8c77381 commit 03c4288

File tree

1 file changed

+71
-42
lines changed

1 file changed

+71
-42
lines changed

02-array-seq/array-seq.ipynb

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,23 +2159,27 @@
21592159
},
21602160
{
21612161
"cell_type": "code",
2162-
"execution_count": 69,
2162+
"execution_count": 4,
21632163
"metadata": {},
21642164
"outputs": [
21652165
{
21662166
"name": "stdout",
21672167
"output_type": "stream",
21682168
"text": [
2169-
" 1 0 LOAD_NAME 0 (s)\n",
2170-
" 2 LOAD_NAME 1 (a)\n",
2171-
" 4 DUP_TOP_TWO\n",
2172-
" 6 BINARY_SUBSCR\n",
2173-
" 8 LOAD_NAME 2 (b)\n",
2174-
" 10 INPLACE_ADD\n",
2175-
" 12 ROT_THREE\n",
2176-
" 14 STORE_SUBSCR\n",
2177-
" 16 LOAD_CONST 0 (None)\n",
2178-
" 18 RETURN_VALUE\n"
2169+
" 0 RESUME 0\n",
2170+
"\n",
2171+
" 1 LOAD_NAME 0 (s)\n",
2172+
" LOAD_NAME 1 (a)\n",
2173+
" COPY 2\n",
2174+
" COPY 2\n",
2175+
" BINARY_OP 26 ([])\n",
2176+
" LOAD_NAME 2 (b)\n",
2177+
" BINARY_OP 13 (+=)\n",
2178+
" SWAP 3\n",
2179+
" SWAP 2\n",
2180+
" STORE_SUBSCR\n",
2181+
" LOAD_CONST 0 (None)\n",
2182+
" RETURN_VALUE\n"
21792183
]
21802184
}
21812185
],
@@ -2192,9 +2196,34 @@
21922196
"## list.sort and the sorted Built-In Function"
21932197
]
21942198
},
2199+
{
2200+
"cell_type": "markdown",
2201+
"metadata": {},
2202+
"source": [
2203+
"> Fluent Interface \n",
2204+
"\n",
2205+
"代表你可以用「**鏈式方法呼叫**」,例如:\n",
2206+
"\n",
2207+
"```python\n",
2208+
"s = \" hello \"\n",
2209+
"result = s.strip().upper().replace(\"HELLO\", \"HI\")\n",
2210+
"print(result) # HI\n",
2211+
"```\n",
2212+
"每個方法都回傳一個新的字串(不是 `None`),讓你可以一直串下去使用,這也是 receiver 的一種連續應用。"
2213+
]
2214+
},
2215+
{
2216+
"cell_type": "markdown",
2217+
"metadata": {},
2218+
"source": [
2219+
"> Python 主排序演算法為 `Timsort`,屬於**穩定**演算法 \n",
2220+
"\n",
2221+
"代表排序時會**保留比較結果相同項目的相對順序** \n"
2222+
]
2223+
},
21952224
{
21962225
"cell_type": "code",
2197-
"execution_count": 70,
2226+
"execution_count": 1,
21982227
"metadata": {},
21992228
"outputs": [
22002229
{
@@ -2203,7 +2232,7 @@
22032232
"['apple', 'banana', 'grape', 'raspberry']"
22042233
]
22052234
},
2206-
"execution_count": 70,
2235+
"execution_count": 1,
22072236
"metadata": {},
22082237
"output_type": "execute_result"
22092238
}
@@ -2215,7 +2244,7 @@
22152244
},
22162245
{
22172246
"cell_type": "code",
2218-
"execution_count": 71,
2247+
"execution_count": 2,
22192248
"metadata": {},
22202249
"outputs": [
22212250
{
@@ -2224,7 +2253,7 @@
22242253
"['grape', 'raspberry', 'apple', 'banana']"
22252254
]
22262255
},
2227-
"execution_count": 71,
2256+
"execution_count": 2,
22282257
"metadata": {},
22292258
"output_type": "execute_result"
22302259
}
@@ -2235,7 +2264,7 @@
22352264
},
22362265
{
22372266
"cell_type": "code",
2238-
"execution_count": 72,
2267+
"execution_count": 3,
22392268
"metadata": {},
22402269
"outputs": [
22412270
{
@@ -2244,7 +2273,7 @@
22442273
"['raspberry', 'grape', 'banana', 'apple']"
22452274
]
22462275
},
2247-
"execution_count": 72,
2276+
"execution_count": 3,
22482277
"metadata": {},
22492278
"output_type": "execute_result"
22502279
}
@@ -2255,7 +2284,7 @@
22552284
},
22562285
{
22572286
"cell_type": "code",
2258-
"execution_count": 73,
2287+
"execution_count": 4,
22592288
"metadata": {},
22602289
"outputs": [
22612290
{
@@ -2264,7 +2293,7 @@
22642293
"['grape', 'apple', 'banana', 'raspberry']"
22652294
]
22662295
},
2267-
"execution_count": 73,
2296+
"execution_count": 4,
22682297
"metadata": {},
22692298
"output_type": "execute_result"
22702299
}
@@ -2275,7 +2304,7 @@
22752304
},
22762305
{
22772306
"cell_type": "code",
2278-
"execution_count": 74,
2307+
"execution_count": 5,
22792308
"metadata": {},
22802309
"outputs": [
22812310
{
@@ -2284,7 +2313,7 @@
22842313
"['raspberry', 'banana', 'grape', 'apple']"
22852314
]
22862315
},
2287-
"execution_count": 74,
2316+
"execution_count": 5,
22882317
"metadata": {},
22892318
"output_type": "execute_result"
22902319
}
@@ -2295,7 +2324,7 @@
22952324
},
22962325
{
22972326
"cell_type": "code",
2298-
"execution_count": 75,
2327+
"execution_count": 6,
22992328
"metadata": {},
23002329
"outputs": [
23012330
{
@@ -2304,7 +2333,7 @@
23042333
"['grape', 'raspberry', 'apple', 'banana']"
23052334
]
23062335
},
2307-
"execution_count": 75,
2336+
"execution_count": 6,
23082337
"metadata": {},
23092338
"output_type": "execute_result"
23102339
}
@@ -2315,7 +2344,7 @@
23152344
},
23162345
{
23172346
"cell_type": "code",
2318-
"execution_count": 76,
2347+
"execution_count": 7,
23192348
"metadata": {},
23202349
"outputs": [
23212350
{
@@ -2324,7 +2353,7 @@
23242353
"['apple', 'banana', 'grape', 'raspberry']"
23252354
]
23262355
},
2327-
"execution_count": 76,
2356+
"execution_count": 7,
23282357
"metadata": {},
23292358
"output_type": "execute_result"
23302359
}
@@ -2357,7 +2386,7 @@
23572386
},
23582387
{
23592388
"cell_type": "code",
2360-
"execution_count": 77,
2389+
"execution_count": 8,
23612390
"metadata": {},
23622391
"outputs": [
23632392
{
@@ -2366,7 +2395,7 @@
23662395
"0.8190492979077034"
23672396
]
23682397
},
2369-
"execution_count": 77,
2398+
"execution_count": 8,
23702399
"metadata": {},
23712400
"output_type": "execute_result"
23722401
}
@@ -2382,7 +2411,7 @@
23822411
},
23832412
{
23842413
"cell_type": "code",
2385-
"execution_count": 78,
2414+
"execution_count": 9,
23862415
"metadata": {},
23872416
"outputs": [],
23882417
"source": [
@@ -2392,7 +2421,7 @@
23922421
},
23932422
{
23942423
"cell_type": "code",
2395-
"execution_count": 79,
2424+
"execution_count": 10,
23962425
"metadata": {},
23972426
"outputs": [
23982427
{
@@ -2401,7 +2430,7 @@
24012430
"0.8190492979077034"
24022431
]
24032432
},
2404-
"execution_count": 79,
2433+
"execution_count": 10,
24052434
"metadata": {},
24062435
"output_type": "execute_result"
24072436
}
@@ -2417,7 +2446,7 @@
24172446
},
24182447
{
24192448
"cell_type": "code",
2420-
"execution_count": 80,
2449+
"execution_count": 11,
24212450
"metadata": {},
24222451
"outputs": [
24232452
{
@@ -2426,7 +2455,7 @@
24262455
"True"
24272456
]
24282457
},
2429-
"execution_count": 80,
2458+
"execution_count": 11,
24302459
"metadata": {},
24312460
"output_type": "execute_result"
24322461
}
@@ -2456,7 +2485,7 @@
24562485
},
24572486
{
24582487
"cell_type": "code",
2459-
"execution_count": 81,
2488+
"execution_count": 12,
24602489
"metadata": {
24612490
"collapsed": false,
24622491
"pycharm": {
@@ -2470,7 +2499,7 @@
24702499
"[0, 1, 2, 3, 4, 5]"
24712500
]
24722501
},
2473-
"execution_count": 81,
2502+
"execution_count": 12,
24742503
"metadata": {},
24752504
"output_type": "execute_result"
24762505
}
@@ -2483,7 +2512,7 @@
24832512
},
24842513
{
24852514
"cell_type": "code",
2486-
"execution_count": 82,
2515+
"execution_count": 13,
24872516
"metadata": {
24882517
"collapsed": false,
24892518
"pycharm": {
@@ -2497,7 +2526,7 @@
24972526
"[[0, 1, 2], [3, 4, 5]]"
24982527
]
24992528
},
2500-
"execution_count": 82,
2529+
"execution_count": 13,
25012530
"metadata": {},
25022531
"output_type": "execute_result"
25032532
}
@@ -2509,7 +2538,7 @@
25092538
},
25102539
{
25112540
"cell_type": "code",
2512-
"execution_count": 83,
2541+
"execution_count": 14,
25132542
"metadata": {
25142543
"collapsed": false,
25152544
"pycharm": {
@@ -2523,7 +2552,7 @@
25232552
"[[0, 1], [2, 3], [4, 5]]"
25242553
]
25252554
},
2526-
"execution_count": 83,
2555+
"execution_count": 14,
25272556
"metadata": {},
25282557
"output_type": "execute_result"
25292558
}
@@ -2535,7 +2564,7 @@
25352564
},
25362565
{
25372566
"cell_type": "code",
2538-
"execution_count": 84,
2567+
"execution_count": 15,
25392568
"metadata": {
25402569
"collapsed": false,
25412570
"pycharm": {
@@ -2549,7 +2578,7 @@
25492578
"array('B', [0, 1, 2, 33, 22, 5])"
25502579
]
25512580
},
2552-
"execution_count": 84,
2581+
"execution_count": 15,
25532582
"metadata": {},
25542583
"output_type": "execute_result"
25552584
}
@@ -2569,7 +2598,7 @@
25692598
},
25702599
{
25712600
"cell_type": "code",
2572-
"execution_count": 85,
2601+
"execution_count": 16,
25732602
"metadata": {},
25742603
"outputs": [
25752604
{
@@ -2578,7 +2607,7 @@
25782607
"5"
25792608
]
25802609
},
2581-
"execution_count": 85,
2610+
"execution_count": 16,
25822611
"metadata": {},
25832612
"output_type": "execute_result"
25842613
}

0 commit comments

Comments
 (0)