Skip to content

Commit 9ec2faf

Browse files
Merge branch 'main' of github.com:UPstartDeveloper/Python-Literacy-Project
2 parents 41d8c44 + cb3d378 commit 9ec2faf

File tree

2 files changed

+3130
-1071
lines changed

2 files changed

+3130
-1071
lines changed

chapter0-exercises/chapter_0_part1.ipynb

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"assert sys.version_info >= (3, 5)"
6565
],
6666
"id": "DYxtfmnM4caC",
67-
"execution_count": 1,
67+
"execution_count": null,
6868
"outputs": []
6969
},
7070
{
@@ -1402,9 +1402,7 @@
14021402
"\n",
14031403
"The definition of the mode is the *most commonly occurring value* or feature across our data.\n",
14041404
"\n",
1405-
"**Hint**: think about how you would solve this problem without code. You will probably need to keep track of the number of times each unique element appears in `data`. How might you use a *histogram* to help you achieve this?\n",
1406-
"\n",
1407-
"[TODO] add diagram of a histogram"
1405+
"**Hint**: think about how you would solve this problem without code. You will probably need to keep track of the number of times each unique element appears in `data`. How might you use a *histogram* to help you achieve this?"
14081406
],
14091407
"id": "dietary-skating"
14101408
},
@@ -1537,10 +1535,11 @@
15371535
"source": [
15381536
"### Solution 2: Using a `Counter`\n",
15391537
"\n",
1538+
"Using the `dict` type is to compute histograms in Python - so often in fact, that the creators of the language decided to also create the `Counter` type.\n",
15401539
"\n",
1541-
"TODO: add explanation\n",
1540+
"Simply put, `Counter` is just a child of the `dict` type with some extra properties. These properties simplify several operations that we typically perform on histograms.\n",
15421541
"\n",
1543-
"[Python documentation](https://docs.python.org/3/library/collections.html#collections.Counter.most_common)\n"
1542+
"For example, let's see how we can find the mode of `dataset` by instantiating a `Counter` object, and then using the `most_commmon()` method:\n"
15441543
],
15451544
"id": "28BJ_7PZbhEy"
15461545
},
@@ -1552,7 +1551,6 @@
15521551
"source": [
15531552
"from collections import Counter\n",
15541553
"\n",
1555-
"\n",
15561554
"def compute_mode_2(dataset):\n",
15571555
" # A: compute the histogram\n",
15581556
" histogram = Counter(dataset)\n",
@@ -1561,9 +1559,19 @@
15611559
" return mode_value"
15621560
],
15631561
"id": "V5AGm-fgdOmE",
1564-
"execution_count": null,
1562+
"execution_count": 1,
15651563
"outputs": []
15661564
},
1565+
{
1566+
"cell_type": "markdown",
1567+
"metadata": {
1568+
"id": "_b6Q_jTh2iHI"
1569+
},
1570+
"source": [
1571+
"For more on the properties of the `Counter`, please visit the [Python documentation](https://docs.python.org/3/library/collections.html#collections.Counter)."
1572+
],
1573+
"id": "_b6Q_jTh2iHI"
1574+
},
15671575
{
15681576
"cell_type": "markdown",
15691577
"metadata": {
@@ -1621,10 +1629,11 @@
16211629
},
16221630
"source": [
16231631
"### Example Input\n",
1632+
"To wrap your head around technical questions like this, it often helps to just ignore all the verbiage - and create an analogy that helps you understand it clearly.\n",
16241633
"\n",
1625-
"TODO: add scoreboard analogy?\n",
1634+
"For example, consider the values in `nums` like the scores of different players on an old, arcade video game machine. And let `k` represent the top highest scores in this game. Now, how would you go about building a scoreboard for this machine (such as shown below) with the top `k` scores listed at the top?\n",
16261635
"\n",
1627-
"Example:\n",
1636+
"Use this example input to guide your thinking:\n",
16281637
"\n",
16291638
"```\n",
16301639
"Inputs:\n",
@@ -2335,10 +2344,12 @@
23352344
"\n",
23362345
"You are given a list of numbers, `nums`, and another integer, `target`. How would you implement Python code to find all the pairs of numbers found in `nums` that sum to `target`?\n",
23372346
"\n",
2347+
"Please return a 2D list of the pairs you find.\n",
2348+
"\n",
23382349
"You may assume that:\n",
23392350
"\n",
2340-
"1. `nums` contains at least 2 integers, is unsorted, and contains no duplicate elements.\n",
2341-
"2. You may return a 2D list of the pairs you find.\n",
2351+
"1. `nums` contains at least 2 integers.\n",
2352+
"2. `nums` is unsorted.\n",
23422353
"3. The ordering of the elements in each pair does not matter."
23432354
],
23442355
"id": "alternate-trust"
@@ -2363,7 +2374,7 @@
23632374
"nums = [3, 5, 2, -4, 8, 11]"
23642375
],
23652376
"id": "7jAsV3CgVmeQ",
2366-
"execution_count": 2,
2377+
"execution_count": null,
23672378
"outputs": []
23682379
},
23692380
{
@@ -2400,7 +2411,7 @@
24002411
" return pairs"
24012412
],
24022413
"id": "guided-kuwait",
2403-
"execution_count": 4,
2414+
"execution_count": null,
24042415
"outputs": [
24052416
{
24062417
"output_type": "stream",
@@ -2434,7 +2445,7 @@
24342445
"print(find_sum_pairs_1(target, nums))"
24352446
],
24362447
"id": "VwYRUIPtVwrp",
2437-
"execution_count": 5,
2448+
"execution_count": null,
24382449
"outputs": [
24392450
{
24402451
"output_type": "stream",
@@ -2476,7 +2487,7 @@
24762487
" return pairs"
24772488
],
24782489
"id": "TLb7wYxS5Ujg",
2479-
"execution_count": 10,
2490+
"execution_count": null,
24802491
"outputs": []
24812492
},
24822493
{
@@ -2502,7 +2513,7 @@
25022513
"print(find_sum_pairs_2(target, nums))"
25032514
],
25042515
"id": "A7fGWqGBV4FQ",
2505-
"execution_count": 11,
2516+
"execution_count": null,
25062517
"outputs": [
25072518
{
25082519
"output_type": "stream",
@@ -2567,7 +2578,7 @@
25672578
"end = [4, 5, 7, 10]"
25682579
],
25692580
"id": "gFas01LmjvpS",
2570-
"execution_count": 12,
2581+
"execution_count": null,
25712582
"outputs": []
25722583
},
25732584
{
@@ -2603,7 +2614,7 @@
26032614
" return max(num_patients)"
26042615
],
26052616
"id": "first-hacker",
2606-
"execution_count": 15,
2617+
"execution_count": null,
26072618
"outputs": []
26082619
},
26092620
{
@@ -2629,7 +2640,7 @@
26292640
"print(find_max_num_patients_1(start, end))"
26302641
],
26312642
"id": "Iv7Sw8PTj3kq",
2632-
"execution_count": 16,
2643+
"execution_count": null,
26332644
"outputs": [
26342645
{
26352646
"output_type": "stream",
@@ -2676,7 +2687,7 @@
26762687
" return max_patient_count"
26772688
],
26782689
"id": "vtujB3xpTzAW",
2679-
"execution_count": 17,
2690+
"execution_count": null,
26802691
"outputs": []
26812692
},
26822693
{
@@ -2702,7 +2713,7 @@
27022713
"print(find_max_num_patients_2(start, end))"
27032714
],
27042715
"id": "T3a3surzkKyh",
2705-
"execution_count": 18,
2716+
"execution_count": null,
27062717
"outputs": [
27072718
{
27082719
"output_type": "stream",
@@ -2755,7 +2766,7 @@
27552766
" return max_patient_count\n"
27562767
],
27572768
"id": "CSstcxCQewSl",
2758-
"execution_count": 19,
2769+
"execution_count": null,
27592770
"outputs": []
27602771
},
27612772
{
@@ -2781,7 +2792,7 @@
27812792
"print(find_max_num_patients_3(start, end))"
27822793
],
27832794
"id": "DyRTM1k_kZ_s",
2784-
"execution_count": 20,
2795+
"execution_count": null,
27852796
"outputs": [
27862797
{
27872798
"output_type": "stream",
@@ -2802,9 +2813,7 @@
28022813
"\n",
28032814
"You are given a list of numbers, `nums`, and are asked to divide it into a certain number of partitions, `n_parts`.\n",
28042815
"\n",
2805-
"How would you implement Python code to perform this task?\n",
2806-
"\n",
2807-
"TODO: should the reader assume we have to return a `list` data type?"
2816+
"How would you implement Python code to perform this task?"
28082817
],
28092818
"id": "nonprofit-sigma"
28102819
},
@@ -2816,7 +2825,7 @@
28162825
"source": [
28172826
"### Example Input\n",
28182827
"\n",
2819-
"You may assume `n_parts` is a nonnegative integer. For simplicity, don't worry about which elements go in which partition."
2828+
"You may assume `n_parts` is a positive integer. For simplicity, don't worry about which elements go in which partition."
28202829
],
28212830
"id": "lqoRQjGclmiH"
28222831
},
@@ -2830,7 +2839,7 @@
28302839
"n_parts = 2"
28312840
],
28322841
"id": "lXWGM8i_l6Mc",
2833-
"execution_count": 21,
2842+
"execution_count": null,
28342843
"outputs": []
28352844
},
28362845
{
@@ -2859,7 +2868,7 @@
28592868
" ]"
28602869
],
28612870
"id": "cathedral-maple",
2862-
"execution_count": 22,
2871+
"execution_count": null,
28632872
"outputs": []
28642873
},
28652874
{
@@ -2885,7 +2894,7 @@
28852894
"print(partition_1(nums, n_parts))"
28862895
],
28872896
"id": "C6tY9jwQmGHG",
2888-
"execution_count": 23,
2897+
"execution_count": null,
28892898
"outputs": [
28902899
{
28912900
"output_type": "stream",
@@ -2923,7 +2932,7 @@
29232932
" return [list(part) for part in reshaped_array]"
29242933
],
29252934
"id": "cpqBscYECoYx",
2926-
"execution_count": 24,
2935+
"execution_count": null,
29272936
"outputs": []
29282937
},
29292938
{
@@ -2959,7 +2968,7 @@
29592968
"print(partition_1(nums, n_parts))"
29602969
],
29612970
"id": "FBeyCa7EmLpW",
2962-
"execution_count": 25,
2971+
"execution_count": null,
29632972
"outputs": [
29642973
{
29652974
"output_type": "stream",
@@ -3018,7 +3027,7 @@
30183027
"threshold = 0.5"
30193028
],
30203029
"id": "religious-cooking",
3021-
"execution_count": 26,
3030+
"execution_count": null,
30223031
"outputs": []
30233032
},
30243033
{
@@ -3044,7 +3053,7 @@
30443053
" print((element, index_row, index_element)) "
30453054
],
30463055
"id": "distributed-emission",
3047-
"execution_count": 27,
3056+
"execution_count": null,
30483057
"outputs": []
30493058
},
30503059
{
@@ -3060,7 +3069,7 @@
30603069
"index_cosine_matrix(matrix, threshold)"
30613070
],
30623071
"id": "hired-nickel",
3063-
"execution_count": 28,
3072+
"execution_count": null,
30643073
"outputs": [
30653074
{
30663075
"output_type": "stream",

0 commit comments

Comments
 (0)