From b4ab5429fc74c9a7300a73f352a583c853c32c27 Mon Sep 17 00:00:00 2001 From: Brody Critchlow Date: Fri, 27 Jan 2023 17:58:14 -0700 Subject: Update list names --- bot/resources/tags/in-place.md | 10 +++++----- 1 file 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. -- cgit v1.2.3