-
-
Notifications
You must be signed in to change notification settings - Fork 750
Add new inplace tag #2388
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
Merged
Merged
Add new inplace tag #2388
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9cb5fe9
Make new tag for #2360
a0bfba5
Update in-place.md
27eb0f9
Update in-place.md
8b2573c
Make explanation more concise, and informational
6bf8e98
Merge branch 'main' into inplace-tag
bb890bb
Add clarifying details
053c5ed
Add clarifying details
c7bc8a0
Add missing code blocks
ae70912
Clarify empty and why it errors.
413cfd3
Small Minimization Changes
aacbdb0
More minimizations
a3ddebe
Clarify words
4aa10ed
Remove empty line
b4ab542
Update list names
83f3167
Clarify comments
d959f76
Update list names, and add clarifying comments
e501492
Update wording
a650c08
Comply to #2419
628d254
Comply to PEP8
cb48b72
Update required wording
26959a1
Change Wording
2760674
Merge branch 'main' into inplace-tag
96bb344
Fix InPlace precommit issues
brodycritchlow 7a69cc5
Merge branch 'main' into inplace-tag
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| embed: | ||
| title: "Out of place and in place" | ||
| --- | ||
|
|
||
| In programming, there are two types of operations: "out of place" operations create a new object, leaving the original object unchanged. "in place" operations modify the original object without creating a new one, and return `None` explicitly. | ||
|
|
||
| A common example of these different concepts is seen in the use of the methods `list.sort()` and `sorted(...)`. Using `list.sort()` and attempting to access an element of the list will result in an error. | ||
|
|
||
| ```py | ||
| # WRONG: | ||
|
|
||
| unsorted_list = [3, 1, 2] | ||
| sorted_list = unsorted_list.sort() # This will be None | ||
| print(sorted_list) # Outputs None. Where did the list go? | ||
|
|
||
| list_to_sort = [3, 1, 2] | ||
| sorted(list_to_sort) | ||
| print(list_to_sort) # The list still isn't sorted. Why? | ||
| ``` | ||
|
|
||
| To avoid these errors and unexpected results, you should either use an out-of-place operation `(sorted(...))` and assign it to a variable or use an in-place operation `(list.sort())` without assignment. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.