Control Flow practice#2
Open
laraib-W wants to merge 2 commits into
Open
Conversation
hsklogix
requested changes
Aug 5, 2022
| @@ -18,12 +18,12 @@ def test_continue_statement(): | |||
|
|
|||
| for number in range(0, 10): | |||
| # Check if remainder after division is zero (which would mean that number is even). | |||
Collaborator
There was a problem hiding this comment.
This comment got staled now, as you've changed the logic.
| # Iterating over a sequence does not implicitly make a copy. The slice notation makes this | ||
| # especially convenient: | ||
| for word in words[:]: # Loop over a slice copy of the entire list. | ||
| for word in words.copy(): # Loop over a slice copy of the entire list. |
Collaborator
There was a problem hiding this comment.
Any reason for changing this?
| # To iterate over the indices of a sequence, you can combine range() and len() as follows: | ||
| words = ['Mary', 'had', 'a', 'little', 'lamb'] | ||
| concatenated_string = '' | ||
| concatenated_string2 = ' '.join(words) |
Collaborator
There was a problem hiding this comment.
This was an example for testing for control, so let's add an example for that.
| concatenated_string += str(word_index) + ' ' + word + ' ' | ||
|
|
||
| assert concatenated_string == 'Mary had a little lamb ' | ||
| assert concatenated_string == '0 Mary 1 had 2 a 3 little 4 lamb ' |
Collaborator
There was a problem hiding this comment.
Let's add a good example for testing the for control.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Practiced control flow python