diff options
author | 2023-01-27 17:58:14 -0700 | |
---|---|---|
committer | 2023-01-27 17:58:14 -0700 | |
commit | b4ab5429fc74c9a7300a73f352a583c853c32c27 (patch) | |
tree | 3b723cb7611e93e8f81ebb81da34ce8e0cd652f6 | |
parent | Remove empty line (diff) |
Update list names
-rw-r--r-- | bot/resources/tags/in-place.md | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/bot/resources/tags/in-place.md b/bot/resources/tags/in-place.md index ca48d4de5..d120f9b08 100644 --- a/bot/resources/tags/in-place.md +++ b/bot/resources/tags/in-place.md @@ -5,13 +5,13 @@ In programming, there are two types of operations: "out of place" operations cre 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 -a_list = [3, 1, 2] -a_new_list = a_list.sort() # This will be None +inplace_list = [3, 1, 2] +a_new_list = inplace_list.sort() # This will be None print(a_new_list[1]) # This will error because it is NoneType and not a list -a_list = [3, 1, 2] -sorted(a_list) -print(a_list[0]) # You may expect 1, but it will print 3 +outofplace_list = [3, 1, 2] +sorted(outofplace_list) +print(outofplace_list[0]) # You may expect 1, but it will print 3 ``` To avoid these errors and unexpected results, it is required to assign the result of `sorted(...)` to a new variable and use `list.sort()` method in the original list. This way, the original list will be sorted and the new list will be created with the sorted elements. |