New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Episode 2: range doesn't return an array #491
Comments
To avoid these problems we can write this point similar to the next ones: Instead of:
We can write as:
Using this approach we omit the explanation of the function return and explain what is the goal of the lesson. |
Thanks for the suggestion. I agree this would be the simplest solution to the problem. However, I'm still a little concerned about the fact that the built-in range function in python3 returns an object of type range. I imagine that if a learner tries to understand what is going on the exercise and type
the learner will not get 0, 1, 2, which is what you would expect from the explanation in the exercise:
I believe this could be rather confusing. |
Indeed, my solution will not help in the case of Python 3. Thank you. How about we create a case just like the ones before, something in the lines of:
|
I don't think we should bother about python 2 as our lesson is python 3. But you are right, the current lesson is a bit confusing because it does not really explain what the built-in range does. |
Instead of introducing the concept of the built-in range function, would it be enough to say that range() does only make sense in the context of a for-loop and should not be used by itself ? |
hmmm, how about |
SWC Python lesson has to have
|
I agree that the bullet points should be reworded and I think @labrax 's wording is pretty accurate (for the stage we are at in the lesson):
Apart from being iterable,
To me the fact that |
100% agree. |
It already says that "
|
Use the phrase "generates a sequence" to use consistent language for lazy-evaluators as iterables in a for loop and avoid suggesting that the sequence is stored as an array in memory. See issue swcarpentry#491.
I agree that using the word "array" here is suggesting an incorrect mental model of the I also agree that
A
So the best language that I can come up with here is "generates a sequence". These terms make sense informally so that the learner gets the idea without being burdened with the implementation of the object or the formalities of the python language reference. They also align with more formal Python language that might be understood later. A Furthermore, the phrase "generates a sequence" is also used in the later |
In episode 2 (Repeating Actions with Loops) the first exercise is called "From 1 to N". This is a good exercise, but I believe its description might give rise to some confusion for novices.
The exercise introduces the concept of looping through the elements of a collection using Python's built-in function "range". On the first bullet point explaining what range does, we have:
However, the function range in Python2 returns a list and in Python3 returns an object of range type. Since learners had just been introduced to lists and arrays and how to find out type(some_thing), it would be important to be consistent and specific about types.
Maybe to avoid going into the details of the type range this early in the lesson, we could simply use numpy.arange (which would return an array) throughout this exercise without compromising its overall goal.
The text was updated successfully, but these errors were encountered: