Add files via upload

This commit is contained in:
Peter Norvig 2024-04-15 22:13:21 -07:00 committed by GitHub
parent ed22a11f69
commit 4db4e41ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -235,7 +235,7 @@
"id": "6e317bd3-dce8-4934-b90a-64a7b76d16d0",
"metadata": {},
"source": [
"I'm not very happy with the docstring for `Segment`. First, the docstring is mixing up two things: what a \"segment\" is, and how it relates to the numbers \"in the list.\" Second, `start` and `end` are better names than `a` and `b` for a segment.\n",
"I'm not very happy with the docstring for `Segment`. First, the docstring is mixing up two things: what a \"segment\" is, and how it relates to the numbers \"in the list.\" Second, `start` and `end` are better names than `a` and `b` for a segment's attributes.\n",
"\n",
"Here's another try at the **docstring**:"
]
@ -258,7 +258,7 @@
"id": "641aa3b9-f716-4a94-bca7-446a5218743e",
"metadata": {},
"source": [
"Now I'll write the **body** for `Segment`. It will be a dataclass with member variables `start` and `end`, abd a magic `repr` method. (A full `Segment` class should probably implement the same methods as `range`, but they are not needed for this problem.)"
"Now I'll write the **body** for `Segment`.(A full `Segment` class should implement all methods of `range`, but they are not needed for this problem.)"
]
},
{
@ -335,7 +335,7 @@
"id": "dfbfb16b-3779-4cdf-a9f1-97d1076e2c91",
"metadata": {},
"source": [
"This is pretty good, but I think it can be improved. The docstring has extraneous text (\"Design a program\") and could be more closely aligned with the body. And it might be more modular to have a function to do one thing (add a single number to a list of segments), rather than a function that organizes all the numbers into a list of segments. I'll edit the **docstring** first to reflect this change:"
"This is pretty good, but I think it can be improved. The docstring has extraneous text (\"Design a program\") and could be more closely aligned with the body. And it might be more modular to have a function to do one thing (add a *single* number to a list of segments), rather than a function that organizes *all* the numbers into a list of segments. I'll edit the **docstring** first to reflect this change:"
]
},
{
@ -396,7 +396,7 @@
"\n",
"def add_to_segment_list(n: int, segment_list: List[Segment]) -> None:\n",
" \"\"\"Mutate `segment_list` to cover `n`. If `n` is one more than the end of the last Segment, \n",
" then add `n` to that last segment. Otherwise append a new Segment (covering `n`) to `segment_list`.\"\"\"\n",
" then add `n` to that last segment. Otherwise append a new Segment (for `n`) to `segment_list`.\"\"\"\n",
" if segment_list and segment_list[-1].end + 1 == n:\n",
" segment_list[-1].end = n\n",
" else:\n",