chore(i18n,learn): processed translations (#54532)

This commit is contained in:
freeCodeCamp's Camper Bot
2024-04-25 11:45:21 -05:00
committed by GitHub
parent c029fe1578
commit 6ae5d0bf3b
3342 changed files with 73085 additions and 3169 deletions
@@ -7,17 +7,16 @@ dashedName: step-13
# --description--
The first kind of cipher you are going to build is called a *Caesar* cipher. Specifically, you will take each letter in your message, find its position in the alphabet, take the letter located after 3 positions, and replace the original letter with the new letter.
Start by finding the position of the first letter in the string. One way is to call the `.find()` string method on the string you want to parse:
You are going to use the `.find()` method to find the position in the alphabet of each letter in your message. A method is similar to a function, but it belongs to an object.
```py
text.find('W')
sentence = 'My brain hurts!'
sentence.find('r')
```
Above, uppercase `'W'` is the character you want to locate inside the string stored in the `text` variable. The method will return `6`, which is the index of the `'W'` character inside the string stored in the `text` variable.
Above, the `.find()` method is *called on* `sentence` (the string to search in), and `'r'` (the character to locate) is passed as the argument. The `sentence.find('r')` call will return `4`, which is the index of the first occurrence of `'r'` in `sentence`.
At the end of your code, call `.find()` on your `alphabet` string and pass `text[0]` to the method. Note that a method is just a function that belongs to an object (you will learn more about that in another project).
At the end of your code, call `.find()` on `alphabet` and pass `'z'` as the argument to the method.
# --hints--
@@ -33,12 +32,14 @@ You should call the `.find()` method on the `alphabet` variable.
assert.match(code, /alphabet\.find\s*\(.*\)/)
```
You should call the `.find()` method on the `alphabet` variable and pass `text[0]` to the method. Pay attention to place the method call at the beginning of the line.
You should call the `.find()` method on the `alphabet` variable and pass `'z'` to the method. Pay attention to place the method call at the beginning of the line.
```js
assert.match(code, /^alphabet\.find\s*\(\s*text\s*\[\s*\s*0\s*\]\s*\)/m)
assert.match(code, /^alphabet\.find\s*\(\s*('|")z\1\s*\)/m)
```
Your code contains invalid syntax and/or invalid indentation.
```js
@@ -1,6 +1,6 @@
---
id: 655208d59b131e7816f18c96
title: Step 14
title: Step 15
challengeType: 20
dashedName: step-15
---
@@ -1,6 +1,6 @@
---
id: 655209a4a27dd37873c4cac3
title: Step 16
title: Step 17
challengeType: 20
dashedName: step-17
---
@@ -1,6 +1,6 @@
---
id: 65520e6f2b9678799977f24d
title: Step 17
title: Step 18
challengeType: 20
dashedName: step-18
---
@@ -1,6 +1,6 @@
---
id: 65520f8282faf57a0db4f7fe
title: Step 20
title: Step 21
challengeType: 20
dashedName: step-21
---
@@ -1,6 +1,6 @@
---
id: 65521203d7165c7b84b22ad4
title: Step 22
title: Step 23
challengeType: 20
dashedName: step-23
---
@@ -1,6 +1,6 @@
---
id: 65521fc818947e800bffe48a
title: Step 27
title: Step 28
challengeType: 20
dashedName: step-28
---
@@ -1,6 +1,6 @@
---
id: 655220953ba90d80514d7ee2
title: Step 28
title: Step 29
challengeType: 20
dashedName: step-29
---
@@ -1,6 +1,6 @@
---
id: 65522255d5b9cd80f335c6f2
title: Step 30
title: Step 31
challengeType: 20
dashedName: step-31
---
@@ -1,6 +1,6 @@
---
id: 6552487e689f6e895f658717
title: Step 34
title: Step 35
challengeType: 20
dashedName: step-35
---
@@ -1,6 +1,6 @@
---
id: 65524b3aa6a1938a069a91ab
title: Step 35
title: Step 36
challengeType: 20
dashedName: step-36
---
@@ -1,6 +1,6 @@
---
id: 65524b790ba8558a2f1c9fe5
title: Step 36
title: Step 37
challengeType: 20
dashedName: step-37
---
@@ -1,6 +1,6 @@
---
id: 65524d2a1a253b8bb5197ae2
title: Step 29
title: Step 30
challengeType: 20
dashedName: step-30
---
@@ -1,6 +1,6 @@
---
id: 655251308f31958d06cdf267
title: Step 37
title: Step 38
challengeType: 20
dashedName: step-38
---
@@ -1,6 +1,6 @@
---
id: 65525e359ca28d938baa82c5
title: Step 40
title: Step 41
challengeType: 20
dashedName: step-41
---
@@ -1,6 +1,6 @@
---
id: 655261b2e1f2c197093f3993
title: Step 42
title: Step 43
challengeType: 20
dashedName: step-43
---
@@ -1,6 +1,6 @@
---
id: 6553980e0527fa115c705646
title: Step 43
title: Step 44
challengeType: 20
dashedName: step-44
---
@@ -1,6 +1,6 @@
---
id: 6553995f412dd8122ed38e4a
title: Step 44
title: Step 45
challengeType: 20
dashedName: step-45
---
@@ -1,6 +1,6 @@
---
id: 6553a44b1801991847d8cc69
title: Step 48
title: Step 49
challengeType: 20
dashedName: step-49
---
@@ -1,6 +1,6 @@
---
id: 6553a572f7a65718f1e42e18
title: Step 50
title: Step 51
challengeType: 20
dashedName: step-51
---
@@ -1,6 +1,6 @@
---
id: 6553a755879b131a445e664c
title: Step 45
title: Step 46
challengeType: 20
dashedName: step-46
---
@@ -1,6 +1,6 @@
---
id: 6553a7d8d05cbb1ae335a665
title: Step 46
title: Step 47
challengeType: 20
dashedName: step-47
---
@@ -1,6 +1,6 @@
---
id: 6553ed69ece88d29594748aa
title: Step 51
title: Step 52
challengeType: 20
dashedName: step-52
---
@@ -1,6 +1,6 @@
---
id: 6553efd6ada3f42aa2d75448
title: Step 52
title: Step 53
challengeType: 20
dashedName: step-53
---
@@ -1,6 +1,6 @@
---
id: 6553f3fc92741c2bf8ded140
title: Step 53
title: Step 54
challengeType: 20
dashedName: step-54
---
@@ -1,6 +1,6 @@
---
id: 6553f4f66099802c6ae94613
title: Step 54
title: Step 55
challengeType: 20
dashedName: step-55
---
@@ -1,6 +1,6 @@
---
id: 6553f6086add4b2cbb99fd78
title: Step 55
title: Step 56
challengeType: 20
dashedName: step-56
---
@@ -1,6 +1,6 @@
---
id: 6553f6b4ec51112d44d737c8
title: Step 49
title: Step 50
challengeType: 20
dashedName: step-50
---
@@ -1,6 +1,6 @@
---
id: 6553f8c570f9982e013a8886
title: Step 56
title: Step 57
challengeType: 20
dashedName: step-57
---
@@ -1,6 +1,6 @@
---
id: 655491bd5b98b813fa5bedca
title: Step 57
title: Step 58
challengeType: 20
dashedName: step-58
---
@@ -1,6 +1,6 @@
---
id: 6554930320d70414e7b6acc6
title: Step 58
title: Step 59
challengeType: 20
dashedName: step-59
---
@@ -1,6 +1,6 @@
---
id: 65549561463f0016876e852c
title: Step 59
title: Step 60
challengeType: 20
dashedName: step-60
---
@@ -1,6 +1,6 @@
---
id: 65549f90cf78131c96ebcf28
title: Step 60
title: Step 61
challengeType: 20
dashedName: step-61
---
@@ -1,6 +1,6 @@
---
id: 6554a334a40edb1fb4eff827
title: Step 61
title: Step 62
challengeType: 20
dashedName: step-62
---
@@ -1,6 +1,6 @@
---
id: 6554a49a4f782f208abcc87e
title: Step 62
title: Step 63
challengeType: 20
dashedName: step-63
---
@@ -1,6 +1,6 @@
---
id: 6554a57ec0a2c52106e7ee50
title: Step 63
title: Step 64
challengeType: 20
dashedName: step-64
---
@@ -1,6 +1,6 @@
---
id: 6554a88d5af937226f4a9121
title: Step 64
title: Step 65
challengeType: 20
dashedName: step-65
---
@@ -1,6 +1,6 @@
---
id: 6554ac937a49be2701af4f2f
title: Step 65
title: Step 66
challengeType: 20
dashedName: step-66
---
@@ -1,6 +1,6 @@
---
id: 6554ad2463b8892748f8efdd
title: Step 66
title: Step 67
challengeType: 20
dashedName: step-67
---
@@ -1,6 +1,6 @@
---
id: 6554d0332949b133a0b35eaa
title: Step 67
title: Step 68
challengeType: 20
dashedName: step-68
---
@@ -1,6 +1,6 @@
---
id: 6554d15c8acb5f34499ad789
title: Step 68
title: Step 69
challengeType: 20
dashedName: step-69
---
@@ -1,6 +1,6 @@
---
id: 6554d25dc5ceaa354307a77e
title: Step 69
title: Step 70
challengeType: 20
dashedName: step-70
---
@@ -1,6 +1,6 @@
---
id: 6554de295ade563a069936a1
title: Step 70
title: Step 71
challengeType: 20
dashedName: step-71
---
@@ -1,6 +1,6 @@
---
id: 6554dfce1683be3c0c9609a6
title: Step 71
title: Step 72
challengeType: 20
dashedName: step-72
---
@@ -1,6 +1,6 @@
---
id: 6554e0adc7bb193cbfdb36d5
title: Step 72
title: Step 73
challengeType: 20
dashedName: step-73
---
@@ -1,6 +1,6 @@
---
id: 6554e2ee23bfd93f2c83640f
title: Step 73
title: Step 74
challengeType: 20
dashedName: step-74
---
@@ -1,6 +1,6 @@
---
id: 6554e343caea913ffba7bec6
title: Step 74
title: Step 75
challengeType: 20
dashedName: step-75
---
@@ -1,6 +1,6 @@
---
id: 655516e410b8e30fb4fb64e8
title: Step 75
title: Step 76
challengeType: 20
dashedName: step-76
---
@@ -1,6 +1,6 @@
---
id: 65551a628bcb7e121e32d04b
title: Step 78
title: Step 79
challengeType: 20
dashedName: step-79
---
@@ -1,6 +1,6 @@
---
id: 6555201d9b7fc917399f9f0b
title: Step 79
title: Step 80
challengeType: 20
dashedName: step-80
---
@@ -1,6 +1,6 @@
---
id: 655520c20cb1e6177b0641d6
title: Step 80
title: Step 81
challengeType: 20
dashedName: step-81
---
@@ -1,6 +1,6 @@
---
id: 655522883e66f618e03a9411
title: Step 81
title: Step 82
challengeType: 20
dashedName: step-82
---
@@ -1,6 +1,6 @@
---
id: 6555231eac4d9f19bd3d44b5
title: Step 82
title: Step 83
challengeType: 20
dashedName: step-83
---
@@ -1,6 +1,6 @@
---
id: 65552a111190e11f0963949e
title: Step 83
title: Step 84
challengeType: 20
dashedName: step-84
---
@@ -1,6 +1,6 @@
---
id: 65552a9593755e1fb2f5ab50
title: Step 84
title: Step 85
challengeType: 20
dashedName: step-85
---
@@ -1,6 +1,6 @@
---
id: 65552b14e803731fe3c1e4ca
title: Step 85
title: Step 86
challengeType: 20
dashedName: step-86
---
@@ -1,6 +1,6 @@
---
id: 65553159615a8123b190ee43
title: Step 86
title: Step 87
challengeType: 20
dashedName: step-87
---
@@ -1,6 +1,6 @@
---
id: 6555d6e12c95701172b55709
title: Step 76
title: Step 77
challengeType: 20
dashedName: step-77
---
@@ -1,6 +1,6 @@
---
id: 6555d8b0b3d20b128bdadd37
title: Step 77
title: Step 78
challengeType: 20
dashedName: step-78
---
@@ -1,6 +1,6 @@
---
id: 6555db4a7b788e15795674e5
title: Step 88
title: Step 89
challengeType: 20
dashedName: step-89
---
@@ -1,6 +1,6 @@
---
id: 6555df0c81300b175308557d
title: Step 89
title: Step 90
challengeType: 20
dashedName: step-90
---
@@ -1,6 +1,6 @@
---
id: 6555e1bfcd374e18c6be8e58
title: Step 90
title: Step 91
challengeType: 20
dashedName: step-91
---
@@ -1,6 +1,6 @@
---
id: 6555e3f387381a19d5e00333
title: Step 91
title: Step 92
challengeType: 20
dashedName: step-92
---
@@ -1,6 +1,6 @@
---
id: 6555e43e783ed31a0532b1b2
title: Step 92
title: Step 93
challengeType: 20
dashedName: step-93
---
@@ -1,6 +1,6 @@
---
id: 6555e547c18a2b1a7b795bd8
title: Step 94
title: Step 95
challengeType: 20
dashedName: step-95
---
@@ -1,6 +1,6 @@
---
id: 6555e5991af57d1ae0e35f0a
title: Step 95
title: Step 96
challengeType: 20
dashedName: step-96
---
@@ -1,6 +1,6 @@
---
id: 655619327c7b364166f8dd6f
title: Step 47
title: Step 48
challengeType: 20
dashedName: step-48
---
@@ -1,6 +1,6 @@
---
id: 655a2a7210094920069b117c
title: Step 41
title: Step 42
challengeType: 20
dashedName: step-42
---
@@ -1,6 +1,6 @@
---
id: 65687d2f8c7ee27b0446cef3
title: Step 23
title: Step 24
challengeType: 20
dashedName: step-24
---
@@ -1,6 +1,6 @@
---
id: 656883980318048fb11a6e3b
title: Step 24
title: Step 25
challengeType: 20
dashedName: step-25
---
@@ -1,6 +1,6 @@
---
id: 656884439d4d7d929d58669d
title: Step 25
title: Step 26
challengeType: 20
dashedName: step-26
---
@@ -1,6 +1,6 @@
---
id: 656886ec4e4d9b96ded3c565
title: Step 26
title: Step 27
challengeType: 20
dashedName: step-27
---
@@ -1,6 +1,6 @@
---
id: 65688a50e6c998a21d8e41d3
title: Step 31
title: Step 32
challengeType: 20
dashedName: step-32
---
@@ -1,6 +1,6 @@
---
id: 65688b5a1655a7a6caede847
title: Step 32
title: Step 33
challengeType: 20
dashedName: step-33
---
@@ -1,6 +1,6 @@
---
id: 6568b7a40c7ba0ccbc4b4425
title: Step 33
title: Step 34
challengeType: 20
dashedName: step-34
---
@@ -1,6 +1,6 @@
---
id: 6568c86dc9193000d11ca5e0
title: Step 39
title: Step 40
challengeType: 20
dashedName: step-40
---
@@ -1,6 +1,6 @@
---
id: 6568cc9301a0c41058ed95c5
title: Step 38
title: Step 39
challengeType: 20
dashedName: step-39
---
@@ -1,6 +1,6 @@
---
id: 659526f3e5424b3eac4b6aa7
title: Step 15
title: Step 16
challengeType: 20
dashedName: step-16
---
@@ -1,6 +1,6 @@
---
id: 65952b70924edb449faf1950
title: Step 18
title: Step 19
challengeType: 20
dashedName: step-19
---
@@ -1,6 +1,6 @@
---
id: 659530ca823d6c47f61daa8a
title: Step 19
title: Step 20
challengeType: 20
dashedName: step-20
---
@@ -1,6 +1,6 @@
---
id: 659db3e3670d3e712be82593
title: Step 21
title: Step 22
challengeType: 20
dashedName: step-22
---
@@ -1,6 +1,6 @@
---
id: 65a450e8fb2c9d75c7378d28
title: Step 87
title: Step 88
challengeType: 20
dashedName: step-88
---
@@ -1,6 +1,6 @@
---
id: 65a51c9e000b660122b8b29e
title: Step 93
title: Step 94
challengeType: 20
dashedName: step-94
---
@@ -17,7 +17,7 @@ You should modify your existing `alphabet.find('z')` call passing `text[0]` to t
```js
assert.match(code, /^alphabet\.find\s*\(\s*text\s*\[\s*0\s*\]\s*\)/m)
```
```
# --seed--
@@ -0,0 +1,42 @@
---
id: 65c4eb814cc977c95cd7df0e
title: Step 1
challengeType: 20
dashedName: step-1
---
# --description--
In this project, you are going to create a Binary Search Tree (BST). A BST is a data structure in which each node has at most two children, with the left child containing values less than the parent node and the right child containing values greater than the parent node, allowing for efficient searching and sorting operations.
This is what a Binary Search Tree looks like:
<img class="img-responsive center-block" alt="a binairy search tree" src="https://cdn.freecodecamp.org/curriculum/python/bst-example.png" style="background-color: white; height:500px; width:500px; padding: 10px;" />
Begin by defining an empty `TreeNode` class. The `TreeNode` class represents a node in a binary search tree. Use the `pass` keyword to fill the class body and avoid an error.
# --hints--
You should use the `class` keyword to declare an empty class named `TreeNode`.
```js
({
test: () => {
assert(__pyodide.runPython(`
import inspect
a = __locals.get("TreeNode")
inspect.isclass(a)
`));
}
})
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,47 @@
---
id: 65c4ef8463f869d0eaf87c67
title: Step 2
challengeType: 20
dashedName: step-2
---
# --description--
Inside the `TreeNode` class, replace `pass` with an `__init__` method so that you can initialize the attributes of the object. Don't add any parameters for now.
# --hints--
You should remove `pass` keyword from the `TreeNode` class and move it inside the `__init__` method.
```js
({
test: () => {
const pyClassStr = runPython(`str(_Node(_code).find_class("TreeNode"))`);
const to_test = pyClassStr.split("\n");
assert.notInclude(to_test[1], "pass");
},
});
```
You should define an `__init__` method inside your `TreeNode` class. Remember to use the `pass` keyword inside.
```js
({
test: () => {
assert(
runPython(`_Node(_code).find_class("TreeNode").has_function("__init__")`)
);
},
});
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
class TreeNode:
pass
--fcc-editable-region--
```
@@ -0,0 +1,38 @@
---
id: 65c4f013851cefd1a4fe4c96
title: Step 3
challengeType: 20
dashedName: step-3
---
# --description--
The `__init__` method takes two parameters: `self` (which represents the instance of the class being created) and `key` (the value to be stored in the node). Add those two parameters to the `__init__()` method.
# --hints--
You should add the `self` parameter to the method.
```js
({ test: () => assert.match(code, /def\s+__init__\s*\(\s*self\s*/) });
```
You should add the `key` parameter to the method.
```js
({
test: () => assert.match(code, /def\s+__init__\s*\(\s*self\s*,\s*key\s*\)/)
});
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
class TreeNode:
def __init__():
pass
--fcc-editable-region--
```
@@ -0,0 +1,47 @@
---
id: 65c4f02dbd3557d23f12db62
title: Step 4
challengeType: 20
dashedName: step-4
---
# --description--
Inside the `__init__` method, delete `pass` and assign the value of the `key` parameter to the `key` attribute of the node using `self.key`.
This means that the `key` attribute of the `TreeNode` instance will be set to the value passed during the object's creation.
# --hints--
You should remove the `pass` statement from the `__init__` method.
```js
({
test: () => {
assert.isFalse(
runPython(
`_Node(_code).find_class("TreeNode").find_function("__init__").has_pass()`
)
);
},
});
```
You should assign the value of the `key` parameter to the `key` attribute of the node using `self.key`.
```js
({ test: () => assert.match(code, /^\s{8}self\.key\s*=\s*key/m) })
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
class TreeNode:
def __init__(self, key):
pass
--fcc-editable-region--
```
@@ -0,0 +1,36 @@
---
id: 65c4f07da204f4d2f325fbd3
title: Step 5
challengeType: 20
dashedName: step-5
---
# --description--
Inside the `__init__` method, initialize the `left` and `right` attributes of the node to `None`. This is because when a node is first created, it doesn't have any left or right children. Remember to use the `self` keyword.
# --hints--
You should assign `None` to the `left` attribute of the node using `self.left`.
```js
({ test: () => assert.match(code, /self\.left\s*=\s*None/m) })
```
You should assign `None` to the `right` attribute of the node using `self.right`.
```js
({ test: () => assert.match(code, /self\.right\s*=\s*None/m) })
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
class TreeNode:
def __init__(self, key):
self.key = key
--fcc-editable-region--
```
@@ -0,0 +1,42 @@
---
id: 65c4f09e074dd8d37830ea00
title: Step 6
challengeType: 20
dashedName: step-6
---
# --description--
Create another empty class called `BinarySearchTree` that represents a binary search tree.
# --hints--
You should have a class named `BinarySearchTree`. Remember to use the `pass` keyword.
```js
({
test: () => {
assert(__pyodide.runPython(`
import inspect
bst = __locals.get("BinarySearchTree")
inspect.isclass(bst)
`));
}
})
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,51 @@
---
id: 65c4f0b82db314d3fcc0b8e1
title: Step 7
challengeType: 20
dashedName: step-7
---
# --description--
Within the `BinarySearchTree` class, replace `pass` with an `__init__` method and add a `self` parameter to this method.
# --hints--
You should remove the `pass` keyword from the `BinarySearchTree` class.
```js
({
test: () => {
const pyClassStr = runPython(
`str(_Node(_code).find_class("BinarySearchTree"))`
);
const to_test = pyClassStr.split("\n");
assert.notInclude(to_test[1], "pass");
},
});
```
You should define an `__init__` method and add a `self` parameter to this method. Remember to use the `pass` keyword inside the method body.
```js
({ test: () => assert.match(code, /^\s{4}def\s+__init__\s*\(\s*self\s*\)\s*:/m) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
--fcc-editable-region--
class BinarySearchTree:
pass
--fcc-editable-region--
```
@@ -0,0 +1,51 @@
---
id: 65c4f0d32ca17ad4b1636b0e
title: Step 8
challengeType: 20
dashedName: step-8
---
# --description--
Inside the `__init__` method, delete `pass` and initialize `root` to the value `None`.
The `root` attribute represents the root node of the binary search tree. Since this is the constructor when a new `BinarySearchTree` object is created, it starts with an empty tree, so the `root` attribute is set to `None`.
# --hints--
You should remove the `pass` statement from the `__init__` method.
```js
({
test: () => {
const pyClassStr = runPython(
`str(_Node(_code).find_class("BinarySearchTree"))`
);
assert.notInclude(pyClassStr, "pass");
},
});
```
You should initialize the `root` attribute to `None` using `self.root`.
```js
({ test: () => assert.match(code, /^\s{8}self\.root\s*=\s*None/m) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
--fcc-editable-region--
class BinarySearchTree:
def __init__(self):
pass
--fcc-editable-region--
```
@@ -0,0 +1,46 @@
---
id: 65c4f195de7e2ad5932be717
title: Step 9
challengeType: 20
dashedName: step-9
---
# --description--
Next, you need to define a mechanism to insert nodes in the tree. For that, you need to define an `_insert` method, which is a helper function and would be used by the actual `insert` method later on.
This method is recursive, meaning it calls itself to traverse the tree until the appropriate location for the new node is found.
Define an `_insert` method with the parameters `self`, `node` and `key`.
# --hints--
You should define an `_insert` method within the `BinarySearchTree` class. Remember to use `pass`.
```js
({ test: () => assert.match(code, /def\s+_insert\s*\([^(]*\)\s*:/m) })
```
Your `_insert` method should take three parameters: `self`, `node` and `key`.
```js
({ test: () => assert.match(code, /def\s+_insert\s*\(\s*self\s*,\s*node\s*,\s*key\s*\)\s*:/m) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
--fcc-editable-region--
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
```
@@ -0,0 +1,73 @@
---
id: 65c4f22498d22ed775ef8efb
title: Step 10
challengeType: 20
dashedName: step-10
---
# --description--
Now you need to check if the `node` parameter is `None`. If it is, this means that the method has reached a leaf node or an empty spot in the tree where the new node should be inserted.
Inside the `_insert` method body, replace `pass` with an `if` statement that checks if `node is None`. Note that `is` is different from `==`. In Python, `is` checks for object identity. It's used to determine if two variables point to the same object in memory. In contrast to `is`, `==` determines if the values of two objects are the same, regardless of whether they are the same object in memory.
Inside the new `if` block, return `TreeNode(key)` to create a new `TreeNode` instance with the provided key. This will become the new leaf node, effectively inserting the key into the tree.
# --hints--
You should not have `pass` in your `_insert` method.
```js
({ test: () => assert.isFalse(runPython(`_Node(_code).find_class("BinarySearchTree").find_function("_insert").has_pass()`)) })
```
You should write an `if` statement to check if `node is None`.
```js
({ test: () =>
{
const transformedCode = code.replace(/\r/g, "");
const ins = __helpers.python.getDef("\n"+transformedCode, "_insert");
const {function_body} = ins;
assert(function_body.match(/^\s{8}if\s+node\s+is\s+None\s*:/m));
}
})
```
You should return `TreeNode(key)` from the `if` block.
```js
({ test: () =>
{
const transformedCode = code.replace(/\r/g, "");
const ins = __helpers.python.getDef("\n"+transformedCode, "_insert");
const {function_body} = ins;
assert(function_body.match(/^(\s{8})if\s+node\s+is\s+None\s*:\s*^\1\s{4}return\s+TreeNode\s*\(\s*key\s*\)/m));
}
})
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
--fcc-editable-region--
class BinarySearchTree:
def __init__(self):
self.root = None
def _insert(self, node, key):
pass
--fcc-editable-region--
```
@@ -0,0 +1,49 @@
---
id: 65c4f2851645e8d84d14f5d1
title: Step 11
challengeType: 20
dashedName: step-11
---
# --description--
Now you need to recursively traverse the tree and insert the values using the principle for binary trees:
- Values smaller than the key are placed in the left subtree
- Values greater than the key are placed in the right subtree
After your existing conditional statement, write another `if` statement to check if `key` is less than `node.key`.
# --hints--
You should write another if statement to check if `key` is less than `node.key`. Remember to use the `pass` keyword.
```js
({ test: () => assert(runPython(` _Node(_code).find_class("BinarySearchTree").find_function("_insert").find_ifs()[1].find_conditions()[0].is_equivalent("key < node.key")`)) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
def _insert(self, node, key):
if node is None:
return TreeNode(key)
--fcc-editable-region--
```
@@ -0,0 +1,69 @@
---
id: 65c4f2b7178afed8e88f782f
title: Step 12
challengeType: 20
dashedName: step-12
---
# --description--
If `key` < `node.key` evaluates to `True`, then the new node should be placed in the left subtree.
Delete `pass` and recursively call the `_insert` method with left child as the first argument and `key` as the second argument. Assign the result to the `left` attribute of the current node.
# --hints--
You should remove the `pass` keyword from the `if` block.
```js
({
test: () => {
assert.isFalse(
runPython(
`_Node(_code).find_class("BinarySearchTree").find_function("_insert").find_if("key < node.key").find_bodies()[0].has_pass()`
)
);
},
});
```
You should call the `self._insert` method passing `node.left` and `key` as the arguments.
```js
({ test: () => assert.match(code, /self\._insert\(\s*node\.left\s*,\s*key\s*\)/) });
```
You should assign the result of your `self._insert()` call to the `left` attribute of the current node.
```js
({ test: () => assert.match(code, /node\.left\s*=\s*self\._insert\(\s*node\.left\s*,\s*key\s*\)/) });
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
def _insert(self, node, key):
if node is None:
return TreeNode(key)
if key < node.key:
pass
--fcc-editable-region--
```
@@ -0,0 +1,49 @@
---
id: 65c4f2d9fd872fd99ac659dd
title: Step 13
challengeType: 20
dashedName: step-13
---
# --description--
Add an `elif` conditional statement that checks if `key` > `node.key`.
# --hints--
You should add an `elif` conditional statement to check if `key > node.key`. Remember to use the `pass` keyword.
```js
({ test: () => assert(runPython(`_Node(_code).find_class("BinarySearchTree").find_function("_insert").find_ifs()[1].find_conditions()[1].is_equivalent("key > node.key")`))})
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
def _insert(self, node, key):
if node is None:
return TreeNode(key)
if key < node.key:
node.left = self._insert(node.left, key)
--fcc-editable-region--
```
@@ -0,0 +1,71 @@
---
id: 65c4f300da28d8da361bfa93
title: Step 14
challengeType: 20
dashedName: step-14
---
# --description--
Inside your `elif` clause, replace `pass` with a call to the `_insert` method with right child of the current node as the first argument and `key` as the second argument. Assign the result to the `right` attribute of the current node.
# --hints--
You should remove the `pass` keyword from the `elif` block.
```js
({
test: () => {
const pyClassStr = runPython(
`str(_Node(_code).find_class("BinarySearchTree"))`
);
assert.notInclude(pyClassStr, "pass");
},
});
```
You should call the `self._insert()` method passing `node.right` and `key` as the arguments.
```js
({ test: () => assert.match(code, /self\._insert\(\s*node\.right\s*,\s*key\s*\)/) });
```
You should assign the result of your `self._insert()` call to the right attribute (`node.right`) of the current node.
```js
({ test: () => assert.match(code, /node\.right\s*=\s*self\._insert\(\s*node\.right\s*,\s*key\s*\)/) });
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
def _insert(self, node, key):
if node is None:
return TreeNode(key)
if key < node.key:
node.left = self._insert(node.left, key)
elif key > node.key:
pass
--fcc-editable-region--
```
@@ -0,0 +1,49 @@
---
id: 65c4f3258d2e4cdacc919dfd
title: Step 15
challengeType: 20
dashedName: step-15
---
# --description--
At the end of your `_insert` method, after the insertion process is complete, return the current node to update the tree structure at the higher levels of the recursive call stack.
# --hints--
You should return the current node outside the conditional blocks.
```js
({ test: () => assert.match(code, /^\s{8}return\s+node/m) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
--fcc-editable-region--
def _insert(self, node, key):
if node is None:
return TreeNode(key)
if key < node.key:
node.left = self._insert(node.left, key)
elif key > node.key:
node.right = self._insert(node.right, key)
--fcc-editable-region--
```
@@ -0,0 +1,47 @@
---
id: 65c4f33bc3c3d8db7f732787
title: Step 16
challengeType: 20
dashedName: step-16
---
# --description--
Now, to perform the actual insertion, define an empty `insert` method within the `BinarySearchTree` class and give it a `self` parameter.
# --hints--
You should define an `insert` method with a `self` parameter within the `BinarySearchTree` class. Remember the `pass` keyword.
```js
({ test: () => assert.match(code, /^\s{4}def\s+insert\s*\(\s*self\s*\)\s*:/m) })
```
# --seed--
## --seed-contents--
```py
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
def _insert(self, node, key):
if node is None:
return TreeNode(key)
if key < node.key:
node.left = self._insert(node.left, key)
elif key > node.key:
node.right = self._insert(node.right, key)
return node
--fcc-editable-region--
--fcc-editable-region--
```

Some files were not shown because too many files have changed in this diff Show More