swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 427 forks source link

Clarify explanation of "How Large is a Slice?" #577

Closed alex-ball closed 2 years ago

alex-ball commented 2 years ago

The solution for "How Large is a Slice?" says the the expression values[low:high], or possibly high - low, will only work if high is less than the total length of the list values. This isn't quite correct on either interpretation.

As shown in Episode 2, values[low:high] will always return a list, even if one or both of the limits are out of bounds. The length of the slice will be high - low if and only if high is equal to or less than the length of the list; it will be zero if both high and low are greater than the length of the list, and somewhere in between otherwise.

This pull request suggests alternative wording that I think would be clearer and more accurate.

alex-ball commented 2 years ago

Yes, good idea. It would certainly help to make the link more obvious.