Skip to content
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

update explanation of the slicing element string #818

Merged
merged 5 commits into from
Apr 3, 2020
Merged

update explanation of the slicing element string #818

merged 5 commits into from
Apr 3, 2020

Conversation

liconlab
Copy link
Contributor

@liconlab liconlab commented Apr 2, 2020

To slice the last three characters, one should use element[-3 : ], which might be a more universal way for any string with length >=3.
Using element[3:6] refers to the 4th to the 6th characters by its literal meaning.

Please delete this line and the text below before submitting your contribution.


Thanks for contributing! If this contribution is for instructor training, please send an email to checkout@carpentries.org with a link to this contribution so we can record your progress. You’ve completed your contribution step for instructor checkout just by submitting this contribution.

Please keep in mind that lesson maintainers are volunteers and it may be some time before they can respond to your contribution. Although not all contributions can be incorporated into the lesson materials, we appreciate your time and effort to improve the curriculum. If you have any questions about the lesson maintenance process or would like to volunteer your time as a contribution reviewer, please contact The Carpentries Team at team@carpentries.org.


To slice the last three characters, one should use element[-3 : ], which might be a more universal way for any string with length >=3. 
Using element[3:6] refers to the 4th to the 6th characters by its literal meaning.
@ldko
Copy link
Contributor

ldko commented Apr 2, 2020

Hi @zhaophotonicslab, congratulations on opening your first Software Carpentry PR! You make a valid point here that if you want a general slice of the last 3 characters of a string you should use [-3 : ]. However, I think where you are making this change, the negative indexing has not yet been introduced. Since in the case of "oxygen", element[3:6] does also give you the last three characters, I suggest we leave that as is, and then add a final part to the Challenge (after the solution for explaining what element[1:-1] does) that asks something like "How can we rewrite the slice for getting the last three characters of element, so that it works on any character string of at least three characters"?

@liconlab
Copy link
Contributor Author

liconlab commented Apr 2, 2020 via email

@ldko
Copy link
Contributor

ldko commented Apr 3, 2020

Hi @zhaophotonicslab, since negative indexing is brought up in the Challenge shortly after where you have made an edit, after that point, we have a good opportunity to show the way you suggest of getting the last three characters. Would you like to modify this Pull Request to change line 508 back to what it was then ask "How can we rewrite the slice for getting the last three characters of element, so it will work on any character string at least three characters in length"? around line 550?

Revert the Line 508 to previous way of slicing the last three characters of element 
Add negative index to slice the last three characters of element in the challenge part
@liconlab
Copy link
Contributor Author

liconlab commented Apr 3, 2020 via email

Copy link
Contributor

@ldko ldko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhaophotonicslab thank you so much for the quick followup and changes! There is no need to open a new pull request. This one will be fine to continue with. These changes look good but need a few minor changes before we can merge them.

_episodes/02-numpy.md Outdated Show resolved Hide resolved
_episodes/02-numpy.md Outdated Show resolved Hide resolved
add > symbol to fix syntax errors
Rephrase questions in Line 550 and Line 551
@liconlab
Copy link
Contributor Author

liconlab commented Apr 3, 2020 via email

_episodes/02-numpy.md Outdated Show resolved Hide resolved
Add more test examples of the challenge of last three character slicing. Add 'carpentry', 'clone', 'hi'
minor fix on the output of last three character slicing
@liconlab
Copy link
Contributor Author

liconlab commented Apr 3, 2020 via email

Copy link
Contributor

@ldko ldko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks great! Thanks very much, @zhaophotonicslab !

Copy link
Contributor

@maxim-belkin maxim-belkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you @zhaophotonicslab! Great job, Lauren!

@maxim-belkin maxim-belkin merged commit f61eed7 into swcarpentry:gh-pages Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants