You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
weekday (int): The weekday number (e.g. 3 for Wednesday).
60
60
ordinal (int): Which weekday of the month (e.g. 2 for the second day).
61
61
@@ -121,13 +121,13 @@ Adya is happy that there are no more nested loops, no mutated state, and 2 fewer
121
121
122
122
She is a little concerned that the recursive approach uses more steps than the looping approach, and so is less "performant".
123
123
But re-writing the problem using recursion has definitely helped her deal with ugly nested looping (_a performance hazard_), extensive state mutation, and confusion around complex conditional logic.
124
-
It also feels more "readable" - she is sure that when she comes back to this code after a break, she will be able to read through and remember what it does more easily.
124
+
It also feels more "readable" — she is sure that when she comes back to this code after a break, she will be able to read through and remember what it does more easily.
125
125
126
126
In the future, Adya may try to work through problems recursively first.
127
127
She may find it easier to initially walk through the problem in clear steps when nesting, mutation, and complexity are minimized.
128
128
After working out the basic logic, she can then focus on optimizing her initial recursive steps into a more performant looping approach.
129
129
130
-
Even later, when she learns about `tuples`, Adya could consider further "optimizing" approaches, such as using a `list comprehension` with `Calendar.itermonthdates`, or memoizing certain values.
130
+
Even later, when she learns about [concept:python/tuples](), Adya could consider further "optimizing" approaches, such as using a [`list comprehension`][list-comprehension] with [`Calendar.itermonthdates`][itermonthssates], or [memoizing][memoization] certain values.
131
131
132
132
133
133
## Recursive Variation: The Tail Call
@@ -187,8 +187,8 @@ However, it is always important when using recursion to know that there will not
187
187
Some languages are able to optimize tail calls so that each recursive call reuses the [stack frame][stack-frame] of the first call to the function (_similar to the way a loop reuses a frame_), instead of adding an additional frame to the stack.
188
188
Python is not one of those languages.
189
189
To guard against stack overflow, Python has a recursion limit that defaults to one thousand frames.
190
-
A [RecursionError](https://docs.python.org/3.8/library/exceptions.html#RecursionError) exception is raised when the interpreter detects that the recursion limit has been exceeded.
191
-
It is possible to use the [sys.setrecursionlimit](https://docs.python.org/3.8/library/sys.html#sys.setrecursionlimit) method to increase the recursion limit, but doing so runs the risk of having a runtime segmentation fault that will crash the program, and possibly the operating system.
190
+
A [RecursionError][RecursionError] exception is raised when the interpreter detects that the recursion limit has been exceeded.
191
+
It is possible to use the [sys.setrecursionlimit][sys.setrecursionlimit] method to increase the recursion limit, but doing so runs the risk of having a runtime segmentation fault that will crash the program, and possibly the operating system.
192
192
193
193
## Resources
194
194
@@ -197,12 +197,16 @@ To learn more about using recursion in Python you can start with
0 commit comments