aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Brody Critchlow <[email protected]>2023-01-28 18:37:37 -0700
committerGravatar GitHub <[email protected]>2023-01-28 18:37:37 -0700
commitd959f7690f919b915c1375704e30de2a1438b8ee (patch)
tree75fb161925a7c6e180b839bd1e64aad8066f0577
parentClarify comments (diff)
Update list names, and add clarifying comments
-rw-r--r--bot/resources/tags/in-place.md14
1 files changed, 8 insertions, 6 deletions
diff --git a/bot/resources/tags/in-place.md b/bot/resources/tags/in-place.md
index 7ed957bdc..0144a840b 100644
--- a/bot/resources/tags/in-place.md
+++ b/bot/resources/tags/in-place.md
@@ -5,13 +5,15 @@ 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
-inplace_list = [3, 1, 2]
-a_new_list = inplace_list.sort() # This will be None
-print(a_new_list) # Outputs None. Where did the list go?
+# WRONG:
-outofplace_list = [3, 1, 2]
-sorted(outofplace_list)
-print(outofplace_list) # The list still isn't sorted. Why?
+unsorted_list = [3, 1, 2]
+sorted_list = inplace_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, 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.