From 413cfd38d7e9af22f7428d3afd16faac63e67d77 Mon Sep 17 00:00:00 2001 From: Brody Critchlow Date: Fri, 27 Jan 2023 13:57:45 -0700 Subject: Small Minimization Changes --- bot/resources/tags/in-place.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bot/resources/tags/in-place.md b/bot/resources/tags/in-place.md index 8c5df89c9..7782175a2 100644 --- a/bot/resources/tags/in-place.md +++ b/bot/resources/tags/in-place.md @@ -2,19 +2,13 @@ In programming, there are two types of operations: "out of place" and "in place". An "out of place" operation creates a new object, leaving the original object unchanged. An "in place" operation modifies the original object, without creating a new one. These operations return None explicitly. -A common example of these different concepts is seen in the use of the methods `list.sort()` and sorted(...) in Python. Using `list.sort()` will modify the original list and return None, so attempting to access an element of the list after calling `sort()` will result in an error. - -For example, the following code will result in an error: +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 after calling `sort()` will result in an error. ```py a_list = [3, 1, 2] a_new_list = a_list.sort() # This will be None print(a_new_list[1]) # This will error because it is NoneType and not a list -``` -On the other hand, using the function `sorted(...)` will return a new sorted list, leaving the original list unchanged. This means that if you expect the original list to be sorted, you will be disappointed with the result. For example, the following code will print 3 instead of 1: - -```py a_list = [3, 1, 2] sorted(a_list) print(a_list[0]) # You may expect 1, but it will print 3 -- cgit v1.2.3