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
There are two examples/exercises whose solutions encourage anti-patterns, miss basic Python features introduced previously, and use the language non-idiomatically. We shouldn't add the confusing cognitive load of "Here's an example, but don't do it this way.".
Intro to the accumulator pattern:
To be worthwhile, the accumulated values should be somewhat non-trivial, students should not leave the session thinking that a for loop is required to merely sum over an iterable:
sum_to_10 = sum(range(1, 11))
This is a missed opportunity to introduce "sum" in the previous built-in functions section.
Solving the problem of range(10) going from 0-9 would be better solved by explaining that one wanted range(1,11) rather than a superfluous extra addition.
If a cheap-and-cheerful Monte-Carlo simulation to estimate Pi is too much, maybe just count the number of heads in some coin-tosses?
Reversing a String:
This is not a good use for a for loop. Slice operators have already been introduced previously, and students should leave thinking that this is how you reverse a string. reversed_string = 'This is not a palindrome![::-1]
Easy. Yes, this demonstrates that iteratively appending items from a collection will cause them to be in reverse order, but why would anyone do that?
The text was updated successfully, but these errors were encountered:
Thanks for the feedback! Minor pedantic note that the simplest way to sum to 10 doesn't need the first parameter, sum(range(11)) suffices.
The string reverse slice operator requires a clear explanation to remove it from the realm of magic but I think it would be a great addition to cement the conceptual model of how slicing works in Python.
There are a fair number of things missing from this lesson in its original incarnation that I believe were deliberate design decisions and that I've attempted to honor during my time as a maintainer with the awareness that this scope / vision should evolve over time alongside the instructors and learners using the course...
list / dict / set comprehensions
lambdas / functions as first class values, example-ridden explanation of call-by-object-reference semantics without the jargon
There is also a discussion on whether to move conditionals up before for loops. For-loop exercises with conditionals should make much more sense and be more intuitive, imho.
There are two examples/exercises whose solutions encourage anti-patterns, miss basic Python features introduced previously, and use the language non-idiomatically. We shouldn't add the confusing cognitive load of "Here's an example, but don't do it this way.".
To be worthwhile, the accumulated values should be somewhat non-trivial, students should not leave the session thinking that a for loop is required to merely sum over an iterable:
This is a missed opportunity to introduce "sum" in the previous built-in functions section.
Solving the problem of range(10) going from 0-9 would be better solved by explaining that one wanted range(1,11) rather than a superfluous extra addition.
If a cheap-and-cheerful Monte-Carlo simulation to estimate Pi is too much, maybe just count the number of heads in some coin-tosses?
This is not a good use for a for loop. Slice operators have already been introduced previously, and students should leave thinking that this is how you reverse a string.
reversed_string = 'This is not a palindrome![::-1]
Easy. Yes, this demonstrates that iteratively appending items from a collection will cause them to be in reverse order, but why would anyone do that?
The text was updated successfully, but these errors were encountered: