From d35ce8d3a09b6b56b02f77fd36b9b23f89a9154d Mon Sep 17 00:00:00 2001 From: larymak Date: Mon, 11 Mar 2024 23:55:03 +0300 Subject: [PATCH 01/20] description improvement --- .../657e928716b77b2277980276.md | 4 ++-- .../657ed53c19461d4b95c4757a.md | 12 ++++++++++-- .../657ee28cefc4945568287673.md | 12 ++++++++++-- .../657ef2a86d4e545cec9a85fb.md | 6 ++++-- .../657efa642593c5746acc5c81.md | 6 +++--- .../657efce98e958b75df86b305.md | 8 +++----- .../657efdcf7fe23b76c0cff9ec.md | 4 +++- .../657effaa2a5e0277d71f9cbe.md | 4 ++-- .../657f0044be09db790b1eb1c5.md | 6 +++--- .../657f01ae9aea647b27402d3e.md | 5 ++++- .../657f025ec86c3d7c4177b6be.md | 4 +++- .../657f04ed0035f47ed04d0f1f.md | 6 ++++-- .../657f4345abe7f2161f99f1ad.md | 4 +--- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 4 ++-- 17 files changed, 57 insertions(+), 34 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index 49cb743dfb51ff..336736f6641bd6 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -7,11 +7,11 @@ dashedName: step-1 # --description-- -In this project, you are going to learn about list comprehensions in Python by building a program that can take a `camelCase` or `PascalCase` formatted string and convert that to a `snake_case` formatted string. +In this project, you are going to learn about list comprehensions in Python by building a program that can take a `camelCase` or `PascalCase` formatted string and convert it into a `snake_case` formatted string. List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster. -Start defining a new function named `convert_to_snake_case()` that accepts a string named `pascal_or_camel_cased_string` as input. For now, add a `pass` statement inside the function. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to mark the starting point of our case conversion. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md index 76aaee9401d837..b8750266443b5b 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md @@ -7,9 +7,17 @@ dashedName: step-2 # --description-- -Now create a new list named `snake_cased_char_list` inside the function. You can use a set of empty square braces to create the new list. +You need to add an empty list that will hold the characters of the string after you have converted them to snake case. -This list will hold the characters of the string after you have converted them to snake case. +In Python, a list is a collection of items that can be of different types. It's denoted by a set of square brackets `[]`. + +```python +# List Example + +my_list = [] +``` + +Inside the function, replace the `pass` statement by creating an empty list named `snake_cased_char_list`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index df97ce81d0d808..59e2a17bf9a162 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -7,9 +7,17 @@ dashedName: step-3 # --description-- -Now that you have an empty list in place, you can start iterating through the input string and start converting each character to snake case. +With the empty list in place, the next step is to iterate through the input string and convert each character to snake case using a `for` loop. -Use a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char` which is short for character. For now, add a `pass` statement in the loop body. +In Python, a `for` loop is used to iterate over a sequence *(like a list, tuple, string)* or other iterable objects. Iterating over a sequence is called traversal. + +```python +# For Loop Example +for variable in sequence: + # code block +``` + +Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement in the loop body. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md index 3cff64a584bed8..bafc0d16102af0 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md @@ -7,9 +7,11 @@ dashedName: step-4 # --description-- -Uppercase characters in camel case or pascal case indicate the start of new words. +In both camel case and pascal case, uppercase characters mark the beginning of new words. To convert the input string to snake case, you will need to check if the characters in the input string are uppercase. -Inside the loop body, use an `if` statement in conjunction with the `.isupper()` string method to check for uppercase characters and move `pass` inside the new `if` statement. +You can use the `.isupper()` string method to check if a character is uppercase. This method returns `True` if the character is uppercase and `False` if it is not. + +Inside the `for` loop, add an `if` statement to check if the current character is uppercase. Move the `pass` statement inside the new `if` statement. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index 9ec8a005e962e0..1ce10ce5fc60b4 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -7,15 +7,15 @@ dashedName: step-5 # --description-- -Inside the `if` statement body, you need to convert any uppercase character to lowercase and prepend an underscore to this lowercase character. +You'll need to transform uppercase characters into lowercase and add an underscore at the beginning of each converted character. -Use the `.lower()` string method to convert uppercase characters to lowercase characters. You can then concatenate an underscore to the character using the plus sign. +To achieve this, the `.lower()` string method is used to convert uppercase characters to lowercase characters. Then concatenate an underscore to the character using the plus sign. ```python '_' + char.lower() ``` -Assign the modified character to a variable named `converted_character` inside the if statement body. +Inside the `if` statement, replace the `pass` statement with the code above and assign the modified character to a variable named `converted_character`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md index e9a0ec849903e6..2670d5dde3fea2 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md @@ -7,13 +7,11 @@ dashedName: step-6 # --description-- -Still within the `if` statement body, use the `.append()` list method to add the converted character to the list you created earlier. +Within the `if` statement's body, we are goin to add the converted character to the list we created earlier. -```py -snake_cased_char_list.append(converted_character) -``` +For this, the `.append()` method will be used. This method adds a given object to the end of the list it is invoked on. -The `.append()` method adds a given object to the end of the list you invoke it on. +Use the `.append()` on the `snake_cased_char_list` to add the `converted_character` to the list. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md index 72b2f5dd928c80..a6713e16fa2d62 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md @@ -7,7 +7,9 @@ dashedName: step-7 # --description-- -Add an `else` clause on the same level as the existing `if` statement, inside the `for` loop. Add characters that are already in lowercase to the list of converted characters inside the body of the `else` clause. +You need to handle the characters that are already in lowercase by adding them to the list of converted characters. + +Right after the `if` statement within the `for` loop add an `else` clause and use the `.append()` to add `char` to the `snake_cased_char_list` variable. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index c2568eaacd0e83..5ed6d41e1c3be6 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -7,13 +7,13 @@ dashedName: step-8 # --description-- -By the end of the loop, `snake_cased_char_list` should contain all the converted characters in correct order. Use the `.join()` string method to convert the list of characters into a string. +By this point, the `snake_cased_char_list` variable contains all the converted characters. You will need to convert the list of characters into a string using the `.join()` method. ```py ''.join(snake_cased_char_list) ``` -This joins the characters from the list to the empty string on which you called the `.join()` method. Save the result in a variable named `snake_cased_string` on the same level as the `snake_cased_char_list` variable. +Right after the `snake_cased_char_list` variable, add a new variable named `snake_cased_string` and assign the result of the `.join()` method given above to it. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 7c4f0407797781..66ce1f26fa2102 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -7,15 +7,15 @@ dashedName: step-9 # --description-- -Strings in pascal case start with a capital character. Since you've converted all such characters to lowercase and prepended an underscore to them, chances are, the converted snake case string has a dangling underscode at the start. +In pascal case, strings begin with a capital letter. After converting all the characters to lowercase and adding an underscore to them, there's a chance of having an extra underscore at the start of your string. -The easiest way to strip such unwanted character is by using the `.strip()` string method and passing an underscore to the method as argument. +The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. ```py snake_cased_string.strip('_') ``` -Make sure to save the resulting string in a variable named `clean_snake_cased_string` on the same level as the `snake_cased_string` variable. +After the `snake_cased_string` variable, add a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method given above to it. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md index c6b3ba9bca8aee..538f64a926f393 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md @@ -7,7 +7,10 @@ dashedName: step-10 # --description-- -Now all that is left to complete this function is to return the `clean_snake_cased_string` from the function. So, go ahead and return the string by adding a `return` statement on the same level as the `clean_snake_cased_string` variable. +To wrap up the fucntion, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. + +Add a `return` statement at the end of the fucntion to return the `clean_snake_cased_string`. + # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md index d669609e5cee9c..6c7de073101d18 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md @@ -7,7 +7,9 @@ dashedName: step-11 # --description-- -Since the function is now complete, put it to use inside another function. Create a new function called `main()` on the same level as the `convert_to_snake_case()` function. +With the fucntion complete, you can now use it inside another function. + +Create a new function called `main()` with `pass` as the body of the function. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 56843f81edb8b7..56fdda1d8e3d87 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -7,9 +7,11 @@ dashedName: step-13 # --description-- -Before running the `main()` function, you need to make sure that the file is running as a script. Add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`. +Before running the `main()` function, you need to make sure that the file is running as a script. -Remember to use `pass` to fill the `if` statement body. +To do this add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`. + +Remember to use `pass` for the `if` statement's body. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 9c054d264db869..6e606a0f455f5d 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -7,9 +7,7 @@ dashedName: step-16 # --description-- -Start by replacing `pass` with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list but do not put anything between the braces. - -Put the braces in separate lines so that you have some space between them, where you can work on the code for the list comprehension. +Replace the `pass` keyword with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index a2969fc86c287b..00d72be56ba2f5 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -7,7 +7,7 @@ dashedName: step-17 # --description-- -Inside the space you left between the pair of square braces, you can describe the value that you would like to include in the list based on a given condition. +Inside the pair of square braces, you can describe the value that you would like to include in the list based on a given condition. ```py snake_cased_char_list = [ diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 74e7eb70237019..7b91bace1348ac 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -7,7 +7,7 @@ dashedName: step-18 # --description-- -When you start a list comprehension with an `if` statement like this, Python requires you to also add an `else` clause to the expression. +When you start a list comprehension with an `if` statement like this, Python requires you to also add an `else` clause. ```py snake_cased_char_list = [ diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 6226601329c245..ca331217653a42 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -21,7 +21,7 @@ snake_cased_char_list = [ And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. -Add this last line of code to iterate over the characters of the string in your list comprehension and make sure that you're writing it within the pair of square braces. +Still within the square braces asfter the `else clause, add this last line of code to iterate over the characters of the string in your list comprehension. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index d159feeb1f4ff9..8367f64f5d92ce 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -7,13 +7,13 @@ dashedName: step-20 # --description-- -You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, let's see a shorter alternative. +You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, here is a shorter alternative. ```py return ''.join(snake_cased_char_list).strip('_') ``` -This single line of code will join the list of characters into a string, strip off any dangling underscores, and return the resulting string. Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function. +Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function. # --hints-- From 873b86bc52cfe094f805d84dcdac3dc55af61dc5 Mon Sep 17 00:00:00 2001 From: larymak Date: Mon, 25 Mar 2024 10:28:10 +0300 Subject: [PATCH 02/20] suggestion resolved --- .../657e928716b77b2277980276.md | 2 +- .../657ee28cefc4945568287673.md | 4 +--- .../657efa642593c5746acc5c81.md | 4 +--- .../657f01ae9aea647b27402d3e.md | 2 +- .../657f025ec86c3d7c4177b6be.md | 2 +- .../657f0353c9523d7d896873ea.md | 4 +++- .../657f465f8e718b19c5105ae5.md | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index 336736f6641bd6..88b29eb78e2314 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -11,7 +11,7 @@ In this project, you are going to learn about list comprehensions in Python by b List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster. -To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to mark the starting point of our case conversion. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to mark the starting point of your case conversion. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index 59e2a17bf9a162..db69d3ab1ab351 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -7,9 +7,7 @@ dashedName: step-3 # --description-- -With the empty list in place, the next step is to iterate through the input string and convert each character to snake case using a `for` loop. - -In Python, a `for` loop is used to iterate over a sequence *(like a list, tuple, string)* or other iterable objects. Iterating over a sequence is called traversal. +With the empty list in place, iterate through the input string and convert each character to snake case using a `for` loop. Iterating over a sequence is called traversal. ```python # For Loop Example diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index 1ce10ce5fc60b4..789da0184376b6 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -7,9 +7,7 @@ dashedName: step-5 # --description-- -You'll need to transform uppercase characters into lowercase and add an underscore at the beginning of each converted character. - -To achieve this, the `.lower()` string method is used to convert uppercase characters to lowercase characters. Then concatenate an underscore to the character using the plus sign. +You'll need to transform uppercase characters into lowercase and add an underscore at the beginning of each converted character. Then concatenate an underscore to the character using the plus sign. ```python '_' + char.lower() diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md index 538f64a926f393..9b94ed41ea73bf 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md @@ -9,7 +9,7 @@ dashedName: step-10 To wrap up the fucntion, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. -Add a `return` statement at the end of the fucntion to return the `clean_snake_cased_string`. +Add a `return` statement at the end of the function to return the `clean_snake_cased_string`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md index 6c7de073101d18..f75d456872c7d8 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md @@ -7,7 +7,7 @@ dashedName: step-11 # --description-- -With the fucntion complete, you can now use it inside another function. +With the function complete, you can now use it inside another function. Create a new function called `main()` with `pass` as the body of the function. diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index 9a2367edf232fe..6926dc4bb159ed 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -7,7 +7,9 @@ dashedName: step-12 # --description-- -Inside the `main()` function, replace `pass` with a `convert_to_snake_case()` call. Pass the string `'aLongAndComplexString'` as input to the function and print out the output using the `print()` function. +Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()`, passing the string `'aLongAndComplexString'` as input. + +To display the output, enclose the fucntion call within the `print()` function. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index ca331217653a42..633168c2bf02bc 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -21,7 +21,7 @@ snake_cased_char_list = [ And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. -Still within the square braces asfter the `else clause, add this last line of code to iterate over the characters of the string in your list comprehension. +Still within the square braces after the `else clause, add this last line of code to iterate over the characters of the string in your list comprehension. # --hints-- From c6396b80620c854b88effcf43b4c4724cc0dce3d Mon Sep 17 00:00:00 2001 From: larymak Date: Thu, 28 Mar 2024 09:19:37 +0300 Subject: [PATCH 03/20] case converter description improvement --- .../657f0353c9523d7d896873ea.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index 6926dc4bb159ed..a17aa4a2543cb8 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -7,9 +7,9 @@ dashedName: step-12 # --description-- -Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()`, passing the string `'aLongAndComplexString'` as input. +Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()` function, pass in the string `'aLongAndComplexString'` as input. -To display the output, enclose the fucntion call within the `print()` function. +To display the output, enclose the function call within the `print()` function. # --hints-- From b7e83da4068c10a4362c02c7b1094ba1b5767ce0 Mon Sep 17 00:00:00 2001 From: larymak Date: Thu, 28 Mar 2024 10:05:23 +0300 Subject: [PATCH 04/20] description improvement --- .../65951b637ddec63611c482c0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/65951b637ddec63611c482c0.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/65951b637ddec63611c482c0.md index 4e76601eb7b7a8..583931c971ad83 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/65951b637ddec63611c482c0.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/65951b637ddec63611c482c0.md @@ -9,7 +9,7 @@ dashedName: step-3 You can use the built-in function `print()` to print the output of your code on the terminal. -Functions are reusable code blocks that you can call (run) when you need them. To call (or invoke) a function, you just need to write a pair of parentheses next to its name. You will learn more about functions very soon. +Functions are reusable code blocks that you can call/run when you need them. To call a function, you just need to write a pair of parentheses next to its name. You will learn more about functions very soon. For now, go to a new line and add an empty call to the `print()` function. You should not see any output yet. From b7aefe48d5350c983f77e72bb716fc9a5ebdfeb7 Mon Sep 17 00:00:00 2001 From: larymak Date: Thu, 28 Mar 2024 12:38:23 +0300 Subject: [PATCH 05/20] Revert "case converter description improvement" This reverts commit c6396b80620c854b88effcf43b4c4724cc0dce3d. --- .../657f0353c9523d7d896873ea.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index a17aa4a2543cb8..6926dc4bb159ed 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -7,9 +7,9 @@ dashedName: step-12 # --description-- -Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()` function, pass in the string `'aLongAndComplexString'` as input. +Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()`, passing the string `'aLongAndComplexString'` as input. -To display the output, enclose the function call within the `print()` function. +To display the output, enclose the fucntion call within the `print()` function. # --hints-- From 4980daf3af8760a9c1c459e3b8dc163fe11d3b55 Mon Sep 17 00:00:00 2001 From: larymak Date: Thu, 28 Mar 2024 13:29:59 +0300 Subject: [PATCH 06/20] case converter suggestion implemetation --- .../657ee28cefc4945568287673.md | 6 ------ .../657f01ae9aea647b27402d3e.md | 2 +- .../657f0353c9523d7d896873ea.md | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index db69d3ab1ab351..6020b550757f28 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -9,12 +9,6 @@ dashedName: step-3 With the empty list in place, iterate through the input string and convert each character to snake case using a `for` loop. Iterating over a sequence is called traversal. -```python -# For Loop Example -for variable in sequence: - # code block -``` - Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement in the loop body. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md index 9b94ed41ea73bf..bd1b81cc11a2d7 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md @@ -7,7 +7,7 @@ dashedName: step-10 # --description-- -To wrap up the fucntion, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. +To wrap up the function, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. Add a `return` statement at the end of the function to return the `clean_snake_cased_string`. diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index 6926dc4bb159ed..e60e8b95b6aa4b 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -7,7 +7,7 @@ dashedName: step-12 # --description-- -Inside the `main()` function, replace the `pass` statement, with a call to `convert_to_snake_case()`, passing the string `'aLongAndComplexString'` as input. +Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input. To display the output, enclose the fucntion call within the `print()` function. From aec131456bf4a1cec7332b29b81fe2cac4076a24 Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 3 Apr 2024 11:34:12 +0300 Subject: [PATCH 07/20] case converter description improvement --- .../657efa642593c5746acc5c81.md | 8 ++------ .../657f0353c9523d7d896873ea.md | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index 789da0184376b6..7dd0abb9bc3517 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -7,13 +7,9 @@ dashedName: step-5 # --description-- -You'll need to transform uppercase characters into lowercase and add an underscore at the beginning of each converted character. Then concatenate an underscore to the character using the plus sign. +Inside the `if` statement body, you need to convert any uppercase character to lowercase and prepend an underscore to this lowercase character. -```python -'_' + char.lower() -``` - -Inside the `if` statement, replace the `pass` statement with the code above and assign the modified character to a variable named `converted_character`. +Use the `.lower()` string method to convert uppercase characters to lowercase characters. Then, prepend an underscore to the character using concatenation. Assign the results to a variable named `converted_character`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index e60e8b95b6aa4b..3263bd7fc19aec 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -9,7 +9,7 @@ dashedName: step-12 Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input. -To display the output, enclose the fucntion call within the `print()` function. +To display the output, enclose the function call within the `print()` function. # --hints-- From 406a7d64d9f9f8a97c1ecf7cc695dc057d282b61 Mon Sep 17 00:00:00 2001 From: larymak Date: Tue, 9 Apr 2024 14:56:23 +0300 Subject: [PATCH 08/20] case converter suggestion improvement --- .../657e928716b77b2277980276.md | 6 +++--- .../657ee28cefc4945568287673.md | 4 ++-- .../657efce98e958b75df86b305.md | 2 +- .../657effaa2a5e0277d71f9cbe.md | 6 +++--- .../657f0044be09db790b1eb1c5.md | 10 +++++++--- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index 88b29eb78e2314..12adeaf5d90972 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -7,11 +7,11 @@ dashedName: step-1 # --description-- -In this project, you are going to learn about list comprehensions in Python by building a program that can take a `camelCase` or `PascalCase` formatted string and convert it into a `snake_case` formatted string. +In this project, you are going to learn about list comprehensions in Python by building a program that converts a `camelCase` or `PascalCase` formatted string into a `snake_case` formatted string. -List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster. +List comprehensions in Python offer a concise way of constructing lists without using loops or the `.append()` method, often resulting in a briefer and faster execution. -To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to mark the starting point of your case conversion. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement as a placeholder, indicating the beginning of the case conversion implementation. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index 6020b550757f28..876a909aca17d7 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -7,9 +7,9 @@ dashedName: step-3 # --description-- -With the empty list in place, iterate through the input string and convert each character to snake case using a `for` loop. Iterating over a sequence is called traversal. +With the empty list in place, iterate through the input string and convert it into snake case using a `for` loop. -Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement in the loop body. +Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement as a placeholder in the loop body. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md index 2670d5dde3fea2..2db1e72e94f701 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md @@ -11,7 +11,7 @@ Within the `if` statement's body, we are goin to add the converted character to For this, the `.append()` method will be used. This method adds a given object to the end of the list it is invoked on. -Use the `.append()` on the `snake_cased_char_list` to add the `converted_character` to the list. +Use the `.append()` method on the `snake_cased_char_list` to add the `converted_character` to the list. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index 5ed6d41e1c3be6..b179c726ddd0d5 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -7,13 +7,13 @@ dashedName: step-8 # --description-- -By this point, the `snake_cased_char_list` variable contains all the converted characters. You will need to convert the list of characters into a string using the `.join()` method. +By this point, the `snake_cased_char_list` variable contains all the converted characters. To convert this list of characters into a string, you'll use the `.join()` method. For example: ```py -''.join(snake_cased_char_list) +result_string = ''.join(characters) ``` -Right after the `snake_cased_char_list` variable, add a new variable named `snake_cased_string` and assign the result of the `.join()` method given above to it. +Right after the `snake_cased_char_list` variable, add a new variable named `snake_cased_string`. Assign it an empty string, then apply the `.join()` method with `snake_cased_char_list` passed as an argument. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 66ce1f26fa2102..4ebfd6426bda47 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -9,13 +9,17 @@ dashedName: step-9 In pascal case, strings begin with a capital letter. After converting all the characters to lowercase and adding an underscore to them, there's a chance of having an extra underscore at the start of your string. -The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. +The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. For example: ```py -snake_cased_string.strip('_') +# String with underscores +original_string = "example_string" + +# Using .strip() method to remove underscores +clean_string = original_string.strip('_') ``` -After the `snake_cased_string` variable, add a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method given above to it. +Add a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` to it. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 7b91bace1348ac..0de2038427e1ca 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -7,7 +7,7 @@ dashedName: step-18 # --description-- -When you start a list comprehension with an `if` statement like this, Python requires you to also add an `else` clause. +When you start a list comprehension with an `if` statement like this, Python filters elements based on the condition provided which means an `else` clause is required to handle the case when the condition is not met. ```py snake_cased_char_list = [ diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 633168c2bf02bc..c58d501b0008e7 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -21,7 +21,7 @@ snake_cased_char_list = [ And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. -Still within the square braces after the `else clause, add this last line of code to iterate over the characters of the string in your list comprehension. +Still within the square braces after the `else` clause, add this last line of code to iterate over the characters of the string in your list comprehension. # --hints-- From 531d9524d99dca91e3f18ebcdd30baf42aac6308 Mon Sep 17 00:00:00 2001 From: larymak Date: Tue, 9 Apr 2024 15:01:49 +0300 Subject: [PATCH 09/20] case converter suggestion improvement --- .../657f456223b8c1187b461987.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 0de2038427e1ca..aec56c811d2eb3 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -7,7 +7,7 @@ dashedName: step-18 # --description-- -When you start a list comprehension with an `if` statement like this, Python filters elements based on the condition provided which means an `else` clause is required to handle the case when the condition is not met. +When you start a list comprehension with an `if` statement like this, Python filters elements based on the condition provided, which means an `else` clause is required to handle the case when the condition is not met. ```py snake_cased_char_list = [ From 059e182cc35c6c2e423ee3011fadbf5a65239e56 Mon Sep 17 00:00:00 2001 From: larymak Date: Tue, 16 Apr 2024 12:10:55 +0300 Subject: [PATCH 10/20] case converter suggestion implementation --- .../657e928716b77b2277980276.md | 2 +- .../657ed53c19461d4b95c4757a.md | 8 -------- .../657efce98e958b75df86b305.md | 2 +- .../657efdcf7fe23b76c0cff9ec.md | 2 +- .../657effaa2a5e0277d71f9cbe.md | 4 +++- .../657f0044be09db790b1eb1c5.md | 2 +- .../657f43d341a0dd17120cdb08.md | 12 ++---------- .../657f456223b8c1187b461987.md | 13 +++---------- .../657f465f8e718b19c5105ae5.md | 16 +++------------- 9 files changed, 15 insertions(+), 46 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index 12adeaf5d90972..172cee861df9ee 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -11,7 +11,7 @@ In this project, you are going to learn about list comprehensions in Python by b List comprehensions in Python offer a concise way of constructing lists without using loops or the `.append()` method, often resulting in a briefer and faster execution. -To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement as a placeholder, indicating the beginning of the case conversion implementation. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to temporarily fill the function body. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md index b8750266443b5b..e68ba396532d44 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md @@ -9,14 +9,6 @@ dashedName: step-2 You need to add an empty list that will hold the characters of the string after you have converted them to snake case. -In Python, a list is a collection of items that can be of different types. It's denoted by a set of square brackets `[]`. - -```python -# List Example - -my_list = [] -``` - Inside the function, replace the `pass` statement by creating an empty list named `snake_cased_char_list`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md index 2db1e72e94f701..35959690a674b3 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md @@ -7,7 +7,7 @@ dashedName: step-6 # --description-- -Within the `if` statement's body, we are goin to add the converted character to the list we created earlier. +Within the `if` statement body, you are going to add the converted character to the list you created earlier. For this, the `.append()` method will be used. This method adds a given object to the end of the list it is invoked on. diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md index a6713e16fa2d62..8959a55a4e812c 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md @@ -9,7 +9,7 @@ dashedName: step-7 You need to handle the characters that are already in lowercase by adding them to the list of converted characters. -Right after the `if` statement within the `for` loop add an `else` clause and use the `.append()` to add `char` to the `snake_cased_char_list` variable. +Right after the `if` statement within the `for` loop, add an `else` clause and use the `.append()` method to add `char` to the `snake_cased_char_list` variable. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index b179c726ddd0d5..a60c8a78268fcc 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -13,7 +13,9 @@ By this point, the `snake_cased_char_list` variable contains all the converted c result_string = ''.join(characters) ``` -Right after the `snake_cased_char_list` variable, add a new variable named `snake_cased_string`. Assign it an empty string, then apply the `.join()` method with `snake_cased_char_list` passed as an argument. +The example above uses an empty string `''` as a separator to join all the characters in a list named `characters`, passed as argument to `.`join()`. + +Right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 4ebfd6426bda47..8b700e9f59a20f 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -13,7 +13,7 @@ The easiest way to fix this is by using the `.strip()` string method and passing ```py # String with underscores -original_string = "example_string" +original_string = "_example_string_" # Using .strip() method to remove underscores clean_string = original_string.strip('_') diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 00d72be56ba2f5..9fd18f6fd73b87 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -7,17 +7,9 @@ dashedName: step-17 # --description-- -Inside the pair of square braces, you can describe the value that you would like to include in the list based on a given condition. +You will need to to convert uppercase characters to lowercase and add an underscore before them. -```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() -] -``` - -Python will interpret this expression as "append `'_' + char.lower()` to the list if `char` is in uppercase" and this will convert the case for the capital letters in the input string. - -Start by adding this line within the square braces. +Within the empty list, implement an `if` statement to check whether the character is uppercase. If it is, append `'_' + char.lower()` to the list. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index aec56c811d2eb3..a30c157330038a 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -7,18 +7,11 @@ dashedName: step-18 # --description-- -When you start a list comprehension with an `if` statement like this, Python filters elements based on the condition provided, which means an `else` clause is required to handle the case when the condition is not met. +When you start a list comprehension with an `if` statement, Python filters elements based on the condition provided, which means an `else` clause is required to handle the case when the condition is not met. -```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char -] -``` - -Python will interpret this updated expression as "append `'_' + char.lower()` to the list if `char` is in uppercase, append `char` as is otherwise" and this covers the case for both the capital and lowercase letters in the input string. +In this case, an `else` clause is needed to ensure that if the condition specified in the `if` statement is not met, `char` is appended to the list as is. -Add an `else` clause inside the pair of square braces. +Add an `else` clause that appends `char` to the list. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index c58d501b0008e7..3ddf3b3fe0873a 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -7,21 +7,11 @@ dashedName: step-19 # --description-- -The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon. +The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon. -In this case, you need to iterate upon all the characters of the string. +In this case, it will iterate upon all the characters of the string, and this can be achieved by making use of a `for` loop. -```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string -] -``` - -And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. - -Still within the square braces after the `else` clause, add this last line of code to iterate over the characters of the string in your list comprehension. +After the `else` clause, add a `for` loop to iterate over the `char` variable in the `pascal_or_camel_cased_string` string. # --hints-- From 065c9cba3da32f4ac2fc5769ea804dabb735d6c5 Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 17 Apr 2024 18:24:43 +0300 Subject: [PATCH 11/20] case converter suggestion implementation --- .../657effaa2a5e0277d71f9cbe.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index a60c8a78268fcc..029a084417b5e7 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -7,15 +7,17 @@ dashedName: step-8 # --description-- -By this point, the `snake_cased_char_list` variable contains all the converted characters. To convert this list of characters into a string, you'll use the `.join()` method. For example: +By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you should utilize the `join()` method. + +The `join` method works by concatenating each element of the list into a string, separated by a designated string, known as the separator. ```py +# join all characters using empty string result_string = ''.join(characters) ``` -The example above uses an empty string `''` as a separator to join all the characters in a list named `characters`, passed as argument to `.`join()`. +Now, right after the `for` loop, use the `join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. -Right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. # --hints-- From ca43574203fe15dcaad47269202d7f0daee84685 Mon Sep 17 00:00:00 2001 From: larymak Date: Fri, 26 Apr 2024 09:33:32 +0300 Subject: [PATCH 12/20] case converter suggestion implementation --- .../657ee28cefc4945568287673.md | 2 +- .../657effaa2a5e0277d71f9cbe.md | 7 ++++--- .../657f0044be09db790b1eb1c5.md | 6 +++--- .../657f0353c9523d7d896873ea.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index 876a909aca17d7..4fcd769a2bb521 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -7,7 +7,7 @@ dashedName: step-3 # --description-- -With the empty list in place, iterate through the input string and convert it into snake case using a `for` loop. +With the empty list in place, now you can start iterating through the input string and convert it into snake case. Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement as a placeholder in the loop body. diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index 029a084417b5e7..17fc7f3aebe2e4 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -7,16 +7,17 @@ dashedName: step-8 # --description-- -By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you should utilize the `join()` method. +By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you can utilize the `.join()` method. The `join` method works by concatenating each element of the list into a string, separated by a designated string, known as the separator. ```py -# join all characters using empty string result_string = ''.join(characters) ``` -Now, right after the `for` loop, use the `join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. +The above example joins together the elements of the `characters` list into a single string where each element is concatenated together without any separator between them. + +Now, right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 8b700e9f59a20f..6960e7e602530e 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -12,14 +12,14 @@ In pascal case, strings begin with a capital letter. After converting all the ch The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. For example: ```py -# String with underscores original_string = "_example_string_" -# Using .strip() method to remove underscores clean_string = original_string.strip('_') ``` -Add a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` to it. +From the example above, the `strip()` method is applied to `original_string`. This removes any leading and trailing characters specified within the parentheses, in this case, underscores. The result of the would be the string `'example_string'`. + +Declare a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index 3263bd7fc19aec..4fe34c9b8520f0 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -9,7 +9,7 @@ dashedName: step-12 Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input. -To display the output, enclose the function call within the `print()` function. +To display the output, pass the function call as the argument to the `print()` function. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 9fd18f6fd73b87..aea0ad36aa3e41 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -7,7 +7,7 @@ dashedName: step-17 # --description-- -You will need to to convert uppercase characters to lowercase and add an underscore before them. +You will need to convert uppercase characters to lowercase and add an underscore before them. Within the empty list, implement an `if` statement to check whether the character is uppercase. If it is, append `'_' + char.lower()` to the list. From 60f975bac666e01e475a58996dd95ddddffc8134 Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 1 May 2024 11:55:36 +0300 Subject: [PATCH 13/20] case converter suggestion implementation --- .../657f43d341a0dd17120cdb08.md | 15 ++++----- .../657f456223b8c1187b461987.md | 18 ++++------- .../657f465f8e718b19c5105ae5.md | 29 ++++++----------- .../657f47b12c51e41b3149e584.md | 32 ++++++------------- 4 files changed, 33 insertions(+), 61 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index aea0ad36aa3e41..73237c3e16d7ea 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -7,20 +7,20 @@ dashedName: step-17 # --description-- -You will need to convert uppercase characters to lowercase and add an underscore before them. +You will need to convert uppercase characters to lowercase and add an underscore before them. Before proceeding, join all the elements of the list `snake_cased_char_list` into a single string using an empty string `''` as the separator. -Within the empty list, implement an `if` statement to check whether the character is uppercase. If it is, append `'_' + char.lower()` to the list. +The using the return statement, return an empty string `''` joined with `snake_cased_char_list` as the argument, and strip any leading or trailing underscores from the result. # --hints-- -You should add `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should return an empty string `''` joined with `snake_cased_char_list`, and ensure to strip any leading or trailing underscores. Ensure the indentation is correct. ```js const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*\]/); +assert.match(function_body, /return\s*''\.join\(snake_cased_char_list\)\.strip\('_'\)/); ``` # --seed-- @@ -41,13 +41,10 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string + snake_cased_char_list = [] --fcc-editable-region-- - snake_cased_char_list = [ - - ] ---fcc-editable-region-- - +--fcc-editable-region-- def main(): print(convert_to_snake_case('aLongAndComplexString')) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index a30c157330038a..7e66e790e09f20 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -7,22 +7,22 @@ dashedName: step-18 # --description-- -When you start a list comprehension with an `if` statement, Python filters elements based on the condition provided, which means an `else` clause is required to handle the case when the condition is not met. +A list comprehension is a concise way to create lists in Python. It consists of an expression followed by a `for` clause or more `for` or `if` clauses allowing iteration over elements from an iterable and optional transformations or condition. -In this case, an `else` clause is needed to ensure that if the condition specified in the `if` statement is not met, `char` is appended to the list as is. +In this step, you will need to convert the empty list `snake_cased_char_list` into a list where each character from `pascal_or_camel_cased_string` is preceded by an underscore and converted to lowercase. -Add an `else` clause that appends `char` to the list. +Inside the empty list `snake_cased_char_list`, transform each `char` into lowercase and add an underscore before it. Add a `for` loop to iterate over each `char` in `pascal_or_camel_cased_string`. # --hints-- -You should add `else char` after `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should add `for char in pascal_or_camel_cased_string` after `'_' + char.lower()` within the square braces of `snake_cased_char_list`. ```js const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s+char\s*\]/); +assert.match(function_body, /'_'\s*\+\s*char\.lower\(\s*\)\s+for\s+char\s+in\s+pascal_or_camel_cased_string/); ``` # --seed-- @@ -44,13 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - - ] + snake_cased_char_list = [] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 3ddf3b3fe0873a..caedeafa80cce0 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -7,26 +7,22 @@ dashedName: step-19 # --description-- -The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon. +List comprehensions are more than just transformation, they can also filter elements based on conditions using `if` statements. You can add an `if` statement within a list comprehension to filter elements based on a given condition. -In this case, it will iterate upon all the characters of the string, and this can be achieved by making use of a `for` loop. +In the previous step, you generated a list of characters from `pascal_or_camel_cased_string`, with each character converted to lowercase and preceded by an underscore. Now, you need to filter out characters that are not uppercase. -After the `else` clause, add a `for` loop to iterate over the `char` variable in the `pascal_or_camel_cased_string` string. +Inside the list comprehension after the `for` clause, add an `if` statement to check if `char` is uppercase. # --hints-- -You should add `for char in pascal_or_camel_cased_string` after `else char` within the square braces of `snake_cased_char_list`. +You should add `if` statement after the `for` clause within the square braces of `snake_cased_char_list` to check if `char` is uppercase. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; - assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*'_'\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s*char\s*for\s+char\s+in\s+pascal_or_camel_cased_string\s*\]/); - } -}) +assert.match(function_body, /if\s*char\.isupper\(\)/); ``` # --seed-- @@ -48,14 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - - ] + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 8367f64f5d92ce..58116d3f97f45b 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -7,28 +7,22 @@ dashedName: step-20 # --description-- -You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, here is a shorter alternative. +List comprehensions not only have the ability to filter elements based on conditions but also perform different transformations depending on the condition. This can be achieved by the use of an `if/else` statement within a list comprehension. -```py -return ''.join(snake_cased_char_list).strip('_') -``` +Previously, you filtered out lowercase characters by adding an `if` statement to check if `char` is uppercase. Now, you will extend the comprehension to handle both cases. -Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function. +Inside the list comprehension, add an `else` clause to ensure that if `char` is not uppercase, it remains unchanged. # --hints-- -You should return `''.join(snake_cased_char_list).strip('_')` at the end of `convert_to_snake_case()` function. +You should add an `else` clause after the `if char.isupper()` statement that ensures `char` is unchanged if it's not uppercase. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; - assert.match(function_body, / +return\s+('|")\1\.join\(\s*snake_cased_char_list\s*\)\.strip\(\s*("|')_\2\s*\)/); - } -}) +assert.match(function_body, /else\s*char/); ``` # --seed-- @@ -50,15 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string - ] - + snake_cased_char_list = ['_' + char.lower() if char.isupper() for char in pascal_or_camel_cased_string] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) From 4947e82f8874bd5ca2102997485c58844a987d19 Mon Sep 17 00:00:00 2001 From: larymak Date: Fri, 24 May 2024 12:10:37 +0300 Subject: [PATCH 14/20] case converter description improvement --- .../meta.json | 18 +++++-- .../657effaa2a5e0277d71f9cbe.md | 4 +- .../657f0044be09db790b1eb1c5.md | 7 ++- .../657f43d341a0dd17120cdb08.md | 10 ++-- .../657f456223b8c1187b461987.md | 50 +++++++++++++---- .../657f465f8e718b19c5105ae5.md | 29 +++++----- .../657f47b12c51e41b3149e584.md | 28 +++++----- .../657f4a4a5828a01de04b652f.md | 4 +- .../657f4add33ea4b1f61ba3dc8.md | 4 +- .../663b10c10a4c0a0e095137ee.md | 54 +++++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 54 +++++++++++++++++++ 11 files changed, 208 insertions(+), 54 deletions(-) create mode 100644 curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md diff --git a/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json b/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json index 58f325de5ab876..fa220e4a7fa711 100644 --- a/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json +++ b/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json @@ -80,24 +80,32 @@ "title": "Step 17" }, { - "id": "657f456223b8c1187b461987", + "id": "663b10c10a4c0a0e095137ee", "title": "Step 18" }, { - "id": "657f465f8e718b19c5105ae5", + "id": "663b16e62fee463b4caf46e9", "title": "Step 19" }, { - "id": "657f47b12c51e41b3149e584", + "id": "657f456223b8c1187b461987", "title": "Step 20" }, { - "id": "657f4a4a5828a01de04b652f", + "id": "657f465f8e718b19c5105ae5", "title": "Step 21" }, { - "id": "657f4add33ea4b1f61ba3dc8", + "id": "657f47b12c51e41b3149e584", "title": "Step 22" + }, + { + "id": "657f4a4a5828a01de04b652f", + "title": "Step 23" + }, + { + "id": "657f4add33ea4b1f61ba3dc8", + "title": "Step 24" } ], "helpCategory": "Python" diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index 17fc7f3aebe2e4..45cc6ad2c0a1bd 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -9,13 +9,13 @@ dashedName: step-8 By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you can utilize the `.join()` method. -The `join` method works by concatenating each element of the list into a string, separated by a designated string, known as the separator. +The `join` method works by concatenating each element of a list into a string, separated by a designated string, known as the separator. ```py result_string = ''.join(characters) ``` -The above example joins together the elements of the `characters` list into a single string where each element is concatenated together without any separator between them. +The example above joins together the elements of the `characters` list into a single string where each element is concatenated together using an empty string as the separator. Now, right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 6960e7e602530e..ea8f1bb8fb3d65 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -9,7 +9,7 @@ dashedName: step-9 In pascal case, strings begin with a capital letter. After converting all the characters to lowercase and adding an underscore to them, there's a chance of having an extra underscore at the start of your string. -The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. For example: +The easiest way to fix this is by using the `.strip()` string method, which removes from a string any leading or trailing characters among a set of characters passed as its argument. For example: ```py original_string = "_example_string_" @@ -17,9 +17,9 @@ original_string = "_example_string_" clean_string = original_string.strip('_') ``` -From the example above, the `strip()` method is applied to `original_string`. This removes any leading and trailing characters specified within the parentheses, in this case, underscores. The result of the would be the string `'example_string'`. +The `strip()` method is applied to `original_string`. This removes any leading and trailing underscore. The result of the example above would be the string `'example_string'`. -Declare a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method. +Declare a new variable named `clean_snake_cased_string` and assign it the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method. # --hints-- @@ -52,6 +52,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): snake_cased_char_list.append(char) --fcc-editable-region-- snake_cased_string = ''.join(snake_cased_char_list) - --fcc-editable-region-- ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 73237c3e16d7ea..e4c53c8c8b1417 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -7,20 +7,22 @@ dashedName: step-17 # --description-- -You will need to convert uppercase characters to lowercase and add an underscore before them. Before proceeding, join all the elements of the list `snake_cased_char_list` into a single string using an empty string `''` as the separator. +You will need to convert uppercase characters to lowercase and add an underscore before them. -The using the return statement, return an empty string `''` joined with `snake_cased_char_list` as the argument, and strip any leading or trailing underscores from the result. +Before proceeding to work on the list comprehension, you're going to give your function a return value. In this way you'll be able to check the output. + +Using the the return statement, return the list `snake_cased_char_list`. # --hints-- -You should return an empty string `''` joined with `snake_cased_char_list`, and ensure to strip any leading or trailing underscores. Ensure the indentation is correct. +You should return the `snake_cased_char_list` list. Ensure the indentation is set correctly. ```js const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; -assert.match(function_body, /return\s*''\.join\(snake_cased_char_list\)\.strip\('_'\)/); +assert.match(function_body, /return\s*snake_cased_char_list/); ``` # --seed-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 7e66e790e09f20..4afbeddfbdf54f 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -1,28 +1,56 @@ --- id: 657f456223b8c1187b461987 -title: Step 18 +title: Step 20 challengeType: 20 -dashedName: step-18 +dashedName: step-20 --- # --description-- -A list comprehension is a concise way to create lists in Python. It consists of an expression followed by a `for` clause or more `for` or `if` clauses allowing iteration over elements from an iterable and optional transformations or condition. +A list comprehension is a concise way to create lists in Python. A basic list comprehension consists of an expression followed by a `for` clause: -In this step, you will need to convert the empty list `snake_cased_char_list` into a list where each character from `pascal_or_camel_cased_string` is preceded by an underscore and converted to lowercase. +```py +spam = [i * 2 for i in iterable] +``` + +The above uses the variable `i` to iterate over `iterable`. Each elements of the resulting list is obtained by evaluating the expression `i * 2` at the current iteration. -Inside the empty list `snake_cased_char_list`, transform each `char` into lowercase and add an underscore before it. Add a `for` loop to iterate over each `char` in `pascal_or_camel_cased_string`. +In this step, you need to fill the empty list `snake_cased_char_list` using the list comprehension syntax. + +Turn your empty list into a list comprehension that converts each character in `pascal_or_camel_cased_string` into a lowercase character and prepends an underscore to it (the code you commented out before may help you write the expression). Use `char` to iterate over `pascal_or_camel_cased_string`. # --hints-- -You should add `for char in pascal_or_camel_cased_string` after `'_' + char.lower()` within the square braces of `snake_cased_char_list`. +You should turn `snake_cased_char_list` into a list comprehension that iterates over `pascal_or_camel_cased_string`. ```js -const transformedCode = code.replace(/\r/g, ""); -const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); -const { function_body } = convert_to_snake_case; +({ + test: () => assert(runPython(` + iters = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_iters() + len(iters) == 1 and iters[0].is_equivalent("pascal_or_camel_cased_string") + `)) +}) +``` + +Your list comprehension should use `char` to iterate over `pascal_or_camel_cased_string`. -assert.match(function_body, /'_'\s*\+\s*char\.lower\(\s*\)\s+for\s+char\s+in\s+pascal_or_camel_cased_string/); +```js +({ + test: () => assert(runPython(` + targets = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_targets() + len(targets) == 1 and targets[0].is_equivalent("char") + `)) +}) +``` + +Your list comprehension should evaluate `'_' + char.lower()` for each `char` in `pascal_or_camel_cased_string`. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").finfind_comp_expr()[0].is_equivalent("'_' + char.lower()") + `)) +}) ``` # --seed-- @@ -46,7 +74,7 @@ def convert_to_snake_case(pascal_or_camel_cased_string): --fcc-editable-region-- snake_cased_char_list = [] --fcc-editable-region-- - return ''.join(snake_cased_char_list).strip('_') + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index caedeafa80cce0..0a4cb55734a539 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -1,28 +1,33 @@ --- id: 657f465f8e718b19c5105ae5 -title: Step 19 +title: Step 21 challengeType: 20 -dashedName: step-19 +dashedName: step-21 --- # --description-- -List comprehensions are more than just transformation, they can also filter elements based on conditions using `if` statements. You can add an `if` statement within a list comprehension to filter elements based on a given condition. +List comprehensions accept conditional statements, to evaluate the provided expression only if certain condition are met: -In the previous step, you generated a list of characters from `pascal_or_camel_cased_string`, with each character converted to lowercase and preceded by an underscore. Now, you need to filter out characters that are not uppercase. +```py +spam = [i * 2 for i in iterable if i > 0] +``` -Inside the list comprehension after the `for` clause, add an `if` statement to check if `char` is uppercase. +As you can see from the output, the list of characters generated from `pascal_or_camel_cased_string` has been joined. Since the expression inside the list comprehension is evaluated for each character, the result is a lowercase string with all the characters separated by an underscore. + +Follow the example above to add an `if` clause to your list comprehension so that the expression is executed only if the character is uppercase. # --hints-- -You should add `if` statement after the `for` clause within the square braces of `snake_cased_char_list` to check if `char` is uppercase. +You should add and `if` clause with the condition `char.isupper()` to your list comprehension. ```js -const transformedCode = code.replace(/\r/g, ""); -const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); -const { function_body } = convert_to_snake_case; - -assert.match(function_body, /if\s*char\.isupper\(\)/); +({ + test: () => assert(runPython(` + ifs = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_ifs() + len(ifs) == 1 and ifs[0].is_equivalent("char.isupper()") + `)) +}) ``` # --seed-- @@ -44,7 +49,7 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string] + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string] --fcc-editable-region-- return ''.join(snake_cased_char_list).strip('_') diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 58116d3f97f45b..79e2476bf07716 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -1,28 +1,32 @@ --- id: 657f47b12c51e41b3149e584 -title: Step 20 +title: Step 22 challengeType: 20 -dashedName: step-20 +dashedName: step-22 --- # --description-- -List comprehensions not only have the ability to filter elements based on conditions but also perform different transformations depending on the condition. This can be achieved by the use of an `if/else` statement within a list comprehension. +Still, the final result is not exactly what you want to achieve. You need to execute a different expression for the characters filtered out by the `if` clause. You'll use an `else` clause for that: -Previously, you filtered out lowercase characters by adding an `if` statement to check if `char` is uppercase. Now, you will extend the comprehension to handle both cases. +```py +spam = [i * 2 if i > 0 else -1 for i in iterable] +``` -Inside the list comprehension, add an `else` clause to ensure that if `char` is not uppercase, it remains unchanged. +Note that, differently from the `if` clause, the `if`/`else` construct must be placed between the expression and the `for` keyword. + +Modify your list comprehension so that when a character is not uppercase it remains unchanged. # --hints-- -You should add an `else` clause after the `if char.isupper()` statement that ensures `char` is unchanged if it's not uppercase. +You should modify your list comprehension to evaluate the expression `'_' + char.lower()` if `char.isupper()` and char otherwise. ```js -const transformedCode = code.replace(/\r/g, ""); -const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); -const { function_body } = convert_to_snake_case; - -assert.match(function_body, /else\s*char/); +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower() if char.isupper() else char") + `)) +}) ``` # --seed-- @@ -44,7 +48,7 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = ['_' + char.lower() if char.isupper() for char in pascal_or_camel_cased_string] + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string if char.isupper()] --fcc-editable-region-- return ''.join(snake_cased_char_list).strip('_') diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 084e1d1686d64c..5e10a7188412fb 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -1,8 +1,8 @@ --- id: 657f4a4a5828a01de04b652f -title: Step 21 +title: Step 23 challengeType: 20 -dashedName: step-21 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 76849d9eac2807..ce7d24e38f9a2b 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -1,8 +1,8 @@ --- id: 657f4add33ea4b1f61ba3dc8 -title: Step 22 +title: Step 24 challengeType: 20 -dashedName: step-22 +dashedName: step-24 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..777a597015fe94 --- /dev/null +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,54 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 18 +challengeType: 0 +dashedName: step-18 +--- + +# --description-- + +After returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the return statement to return the list `snake_cased_char_list` joined with an empty string as a separator. + +# --hints-- + +You should modify the return statement to join the `snake_cased_char_list` using the `join` method with an empty string `''` as the separator. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)); +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +if __name__ == '__main__': + main() +``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..eaf0c33da5b42e --- /dev/null +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,54 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 19 +challengeType: 0 +dashedName: step-19 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Modify the return statement to return the joined `snake_cased_char_list` with the `strip` method applied to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +if __name__ == '__main__': + main() +``` From 8d4bc4becc2dc7a3f576ec364702f4594132797e Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 29 May 2024 12:08:39 +0300 Subject: [PATCH 15/20] case converter description improvement --- .../657f04ed0035f47ed04d0f1f.md | 10 ++- .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 4 +- .../657f4345abe7f2161f99f1ad.md | 4 +- .../657f43d341a0dd17120cdb08.md | 6 +- .../657f456223b8c1187b461987.md | 6 +- .../657f465f8e718b19c5105ae5.md | 8 +-- .../657f47b12c51e41b3149e584.md | 4 +- .../657f4a4a5828a01de04b652f.md | 4 +- .../657f4add33ea4b1f61ba3dc8.md | 4 +- .../663b10c10a4c0a0e095137ee.md | 14 ++--- .../663b16e62fee463b4caf46e9.md | 15 ++++- 12 files changed, 43 insertions(+), 99 deletions(-) delete mode 100644 curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 56fdda1d8e3d87..61d213db0cdbe0 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -7,21 +7,19 @@ dashedName: step-13 # --description-- -Before running the `main()` function, you need to make sure that the file is running as a script. +In order to display the output of the `convert_to_snake_case()` function, you need to call the `main()` function. -To do this add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`. - -Remember to use `pass` for the `if` statement's body. +At the same level as the two existing functions, add a call to the `main()` function. You should see the given camel or pascal cased string converted to snake case upon execution. # --hints-- -You should write a `if` clause to check whether `__name__ == '__main__'` evaluates to `True` or not. Don't forget the colon at the end and use `pass` to fill the `if` body. +You should add a call to the `main()` function. ```js ({ test: () => { const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\nif\s+__name__\s*==\s*("|')__main__\1\s*:/); + assert.match(transformedCode, /\n +main\s*\(\s*\)/); } }) ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 2d868e69202b69..00000000000000 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Step 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index ad4cbe41f6c985..4c1d6c9f113513 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -1,8 +1,8 @@ --- id: 657f425dbab54e11993c80f0 -title: Step 15 +title: Step 14 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 6e606a0f455f5d..e3e1db25538c86 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -1,8 +1,8 @@ --- id: 657f4345abe7f2161f99f1ad -title: Step 16 +title: Step 15 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index e4c53c8c8b1417..9db7ee34bab25c 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -1,8 +1,8 @@ --- id: 657f43d341a0dd17120cdb08 -title: Step 17 +title: Step 16 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- @@ -11,7 +11,7 @@ You will need to convert uppercase characters to lowercase and add an underscore Before proceeding to work on the list comprehension, you're going to give your function a return value. In this way you'll be able to check the output. -Using the the return statement, return the list `snake_cased_char_list`. +Use the `return` statement to return the list `snake_cased_char_list` from your function. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 4afbeddfbdf54f..f7bf7897df312e 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -1,8 +1,8 @@ --- id: 657f456223b8c1187b461987 -title: Step 20 +title: Step 19 challengeType: 20 -dashedName: step-20 +dashedName: step-19 --- # --description-- @@ -48,7 +48,7 @@ Your list comprehension should evaluate `'_' + char.lower()` for each `char` in ```js ({ test: () => assert(runPython(` - _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").finfind_comp_expr()[0].is_equivalent("'_' + char.lower()") + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower()") `)) }) ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 0a4cb55734a539..bb3b386e5dcadf 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -1,13 +1,13 @@ --- id: 657f465f8e718b19c5105ae5 -title: Step 21 +title: Step 20 challengeType: 20 -dashedName: step-21 +dashedName: step-20 --- # --description-- -List comprehensions accept conditional statements, to evaluate the provided expression only if certain condition are met: +List comprehensions accept conditional statements, to evaluate the provided expression only if certain conditions are met: ```py spam = [i * 2 for i in iterable if i > 0] @@ -19,7 +19,7 @@ Follow the example above to add an `if` clause to your list comprehension so tha # --hints-- -You should add and `if` clause with the condition `char.isupper()` to your list comprehension. +You should add an `if` clause with the condition `char.isupper()` to your list comprehension. ```js ({ diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 79e2476bf07716..3a6d57a7c633cc 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -1,8 +1,8 @@ --- id: 657f47b12c51e41b3149e584 -title: Step 22 +title: Step 21 challengeType: 20 -dashedName: step-22 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 5e10a7188412fb..bc1b48db061323 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -1,8 +1,8 @@ --- id: 657f4a4a5828a01de04b652f -title: Step 23 +title: Step 22 challengeType: 20 -dashedName: step-23 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index ce7d24e38f9a2b..c769a4021080c8 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -1,8 +1,8 @@ --- id: 657f4add33ea4b1f61ba3dc8 -title: Step 24 +title: Step 23 challengeType: 20 -dashedName: step-24 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md index 777a597015fe94..527be5d0a8154e 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -1,25 +1,25 @@ --- id: 663b10c10a4c0a0e095137ee -title: Step 18 -challengeType: 0 -dashedName: step-18 +title: Step 17 +challengeType: 20 +dashedName: step-17 --- # --description-- -After returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. -Modify the return statement to return the list `snake_cased_char_list` joined with an empty string as a separator. +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. # --hints-- -You should modify the return statement to join the `snake_cased_char_list` using the `join` method with an empty string `''` as the separator. +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. ```js ({ test: () => assert(runPython(` _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') - `)); + `)) }) ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md index eaf0c33da5b42e..b57e6128eb147e 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -1,14 +1,23 @@ --- id: 663b16e62fee463b4caf46e9 -title: Step 19 -challengeType: 0 -dashedName: step-19 +title: Step 18 +challengeType: 20 +dashedName: step-18 --- # --description-- After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `join` method is called on the list `words_list`, and the result is used as the object for the `upper` method call. + Modify the return statement to return the joined `snake_cased_char_list` with the `strip` method applied to remove any leading or trailing underscores. # --hints-- From 4e3c0ab4e39662e374edae6ca439476a42dc4a75 Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 29 May 2024 12:16:58 +0300 Subject: [PATCH 16/20] case converter step update --- .../meta.json | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json b/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json index fa220e4a7fa711..61410918fb96f8 100644 --- a/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json +++ b/curriculum/challenges/_meta/learn-list-comprehension-by-building-a-case-converter-program/meta.json @@ -63,49 +63,45 @@ "id": "657f04ed0035f47ed04d0f1f", "title": "Step 13" }, - { - "id": "657f28a0482132aca51a9212", - "title": "Step 14" - }, { "id": "657f425dbab54e11993c80f0", - "title": "Step 15" + "title": "Step 14" }, { "id": "657f4345abe7f2161f99f1ad", - "title": "Step 16" + "title": "Step 15" }, { "id": "657f43d341a0dd17120cdb08", - "title": "Step 17" + "title": "Step 16" }, { "id": "663b10c10a4c0a0e095137ee", - "title": "Step 18" + "title": "Step 17" }, { "id": "663b16e62fee463b4caf46e9", - "title": "Step 19" + "title": "Step 18" }, { "id": "657f456223b8c1187b461987", - "title": "Step 20" + "title": "Step 19" }, { "id": "657f465f8e718b19c5105ae5", - "title": "Step 21" + "title": "Step 20" }, { "id": "657f47b12c51e41b3149e584", - "title": "Step 22" + "title": "Step 21" }, { "id": "657f4a4a5828a01de04b652f", - "title": "Step 23" + "title": "Step 22" }, { "id": "657f4add33ea4b1f61ba3dc8", - "title": "Step 24" + "title": "Step 23" } ], "helpCategory": "Python" From 93eeddb3c677530f8c65ea5addc8e0e670118763 Mon Sep 17 00:00:00 2001 From: larymak Date: Thu, 30 May 2024 10:19:05 +0300 Subject: [PATCH 17/20] case converter suggestion implementation --- .../657f425dbab54e11993c80f0.md | 3 +-- .../657f4345abe7f2161f99f1ad.md | 3 +-- .../657f43d341a0dd17120cdb08.md | 3 +-- .../657f456223b8c1187b461987.md | 3 +-- .../657f465f8e718b19c5105ae5.md | 3 +-- .../657f47b12c51e41b3149e584.md | 3 +-- .../657f4a4a5828a01de04b652f.md | 3 +-- .../657f4add33ea4b1f61ba3dc8.md | 8 ++------ .../663b10c10a4c0a0e095137ee.md | 3 +-- .../663b16e62fee463b4caf46e9.md | 7 +++---- 10 files changed, 13 insertions(+), 26 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 4c1d6c9f113513..45ba700555040e 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -51,7 +51,6 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index e3e1db25538c86..10047b0fe727f3 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -51,6 +51,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 9db7ee34bab25c..afaab8a276f46f 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -51,6 +51,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index f7bf7897df312e..62edf28daef9ed 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -79,6 +79,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index bb3b386e5dcadf..a30bf0c9b05dab 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -56,6 +56,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 3a6d57a7c633cc..fea2df988fe71d 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -55,6 +55,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index bc1b48db061323..445e22198e0785 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -56,6 +56,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index c769a4021080c8..aa2269460297e3 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -51,8 +51,7 @@ def main(): --fcc-editable-region-- -if __name__ == '__main__': - main() +main() ``` # --solutions-- @@ -71,8 +70,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('IAmAPascalCasedString')) - - -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md index 527be5d0a8154e..4c3596601b944c 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -49,6 +49,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md index b57e6128eb147e..7b535b7fd106f7 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -16,9 +16,9 @@ words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] result = ' '.join(words_list).upper() ``` -In the example above, the `join` method is called on the list `words_list`, and the result is used as the object for the `upper` method call. +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. -Modify the return statement to return the joined `snake_cased_char_list` with the `strip` method applied to remove any leading or trailing underscores. +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. # --hints-- @@ -58,6 +58,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` From 8849253ba8b569cfcce9ec1ba92519508198ed1f Mon Sep 17 00:00:00 2001 From: Hillary Nyakundi Date: Tue, 11 Jun 2024 23:36:09 +0300 Subject: [PATCH 18/20] update tests for step 13 --- .../657f04ed0035f47ed04d0f1f.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 61d213db0cdbe0..cd0c3961ae2edf 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -17,11 +17,12 @@ You should add a call to the `main()` function. ```js ({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) + test: () => { + const pythonCode = `_Node(_code.replace('\\\\r', '')).has_call("main()")`; + const result = runPython(pythonCode); + assert(result); + } +}); ``` # --seed-- From 9b6887cafd81c0d5364fbe1aacd36efac9328532 Mon Sep 17 00:00:00 2001 From: larymak Date: Wed, 12 Jun 2024 00:04:43 +0300 Subject: [PATCH 19/20] case converter suggestion implementation --- .../657efa642593c5746acc5c81.md | 2 +- .../657f04ed0035f47ed04d0f1f.md | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index 7dd0abb9bc3517..a2e70f734922c6 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -9,7 +9,7 @@ dashedName: step-5 Inside the `if` statement body, you need to convert any uppercase character to lowercase and prepend an underscore to this lowercase character. -Use the `.lower()` string method to convert uppercase characters to lowercase characters. Then, prepend an underscore to the character using concatenation. Assign the results to a variable named `converted_character`. +Use the `.lower()` string method to convert uppercase characters to lowercase characters. Then, prepend an underscore to the character. Assign the results to a variable named `converted_character`. # --hints-- diff --git a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 61d213db0cdbe0..cd0c3961ae2edf 100644 --- a/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/english/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -17,11 +17,12 @@ You should add a call to the `main()` function. ```js ({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) + test: () => { + const pythonCode = `_Node(_code.replace('\\\\r', '')).has_call("main()")`; + const result = runPython(pythonCode); + assert(result); + } +}); ``` # --seed-- From 8a4c8a066a52c967219e197d1920fe3dd59d7079 Mon Sep 17 00:00:00 2001 From: Dario-DC <105294544+Dario-DC@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:22:56 +0200 Subject: [PATCH 20/20] i18n sync --- .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657e928716b77b2277980276.md | 6 +- .../657ed53c19461d4b95c4757a.md | 6 +- .../657ee28cefc4945568287673.md | 4 +- .../657ef2a86d4e545cec9a85fb.md | 6 +- .../657efa642593c5746acc5c81.md | 8 +-- .../657efce98e958b75df86b305.md | 8 +-- .../657efdcf7fe23b76c0cff9ec.md | 4 +- .../657effaa2a5e0277d71f9cbe.md | 11 +++- .../657f0044be09db790b1eb1c5.md | 13 ++-- .../657f01ae9aea647b27402d3e.md | 7 ++- .../657f025ec86c3d7c4177b6be.md | 4 +- .../657f0353c9523d7d896873ea.md | 4 +- .../657f04ed0035f47ed04d0f1f.md | 17 ++--- .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 7 +-- .../657f4345abe7f2161f99f1ad.md | 11 ++-- .../657f43d341a0dd17120cdb08.md | 28 +++------ .../657f456223b8c1187b461987.md | 60 +++++++++++------- .../657f465f8e718b19c5105ae5.md | 45 +++++-------- .../657f47b12c51e41b3149e584.md | 39 +++++------- .../657f4a4a5828a01de04b652f.md | 9 ++- .../657f4add33ea4b1f61ba3dc8.md | 14 ++--- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657e928716b77b2277980276.md | 8 +-- .../657ed53c19461d4b95c4757a.md | 6 +- .../657ee28cefc4945568287673.md | 6 +- .../657ef2a86d4e545cec9a85fb.md | 8 ++- .../657efa642593c5746acc5c81.md | 10 +-- .../657efce98e958b75df86b305.md | 10 ++- .../657efdcf7fe23b76c0cff9ec.md | 6 +- .../657effaa2a5e0277d71f9cbe.md | 13 ++-- .../657f0044be09db790b1eb1c5.md | 15 +++-- .../657f01ae9aea647b27402d3e.md | 7 ++- .../657f025ec86c3d7c4177b6be.md | 6 +- .../657f0353c9523d7d896873ea.md | 6 +- .../657f04ed0035f47ed04d0f1f.md | 19 +++--- .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 7 +-- .../657f4345abe7f2161f99f1ad.md | 11 ++-- .../657f43d341a0dd17120cdb08.md | 28 +++------ .../657f456223b8c1187b461987.md | 60 +++++++++++------- .../657f465f8e718b19c5105ae5.md | 45 +++++-------- .../657f47b12c51e41b3149e584.md | 39 +++++------- .../657f4a4a5828a01de04b652f.md | 9 ++- .../657f4add33ea4b1f61ba3dc8.md | 16 ++--- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ .../657f28a0482132aca51a9212.md | 63 ------------------- .../657f425dbab54e11993c80f0.md | 2 +- .../657f4345abe7f2161f99f1ad.md | 2 +- .../657f43d341a0dd17120cdb08.md | 2 +- .../657f456223b8c1187b461987.md | 2 +- .../657f465f8e718b19c5105ae5.md | 2 +- .../657f47b12c51e41b3149e584.md | 2 +- .../657f4a4a5828a01de04b652f.md | 2 +- .../657f4add33ea4b1f61ba3dc8.md | 2 +- .../663b10c10a4c0a0e095137ee.md | 53 ++++++++++++++++ .../663b16e62fee463b4caf46e9.md | 62 ++++++++++++++++++ 147 files changed, 1645 insertions(+), 1103 deletions(-) delete mode 100644 curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md delete mode 100644 curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md create mode 100644 curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md create mode 100644 curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index f77af490117ead..00000000000000 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: الخطوة 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 8d38e50048d3ae..26e095c1bb1bda 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: الخطوة 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 82961a320a37f9..8e5b621e92bce2 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: الخطوة 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index cd7efab3e647a4..33befeb3f689e5 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: الخطوة 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index b9f2c2c79809a8..864224e62a4894 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: الخطوة 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 265845ae7f967d..5f614cbaa88994 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: الخطوة 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 7757384f8fa83d..0671781dcf8919 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: الخطوة 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 0aa84e65ca8bdb..da6e8c37272812 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: الخطوة 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 9619247c586e57..334c676c6bfd9a 100644 --- a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: الخطوة 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/arabic/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index fb95444e5edb5b..00000000000000 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: 第 14 步 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 26f5879338da6a..8eb8f5a72b6c28 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: 步驟15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 416173939b1da0..dbe44206615503 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: 步驟 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index a14ede788659b3..0acee19ec87ef0 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Step 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 90d49d1407ca7c..3e916e67fb718d 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: 步驟 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 10c3da7ac85d53..394db9385398a7 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: 步驟 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index e22e80d812b2a3..a809116209c191 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: 步驟 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index e34c90fbc58651..325a55f4622383 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: 步驟21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index c4d099e515749b..ac618a337a6393 100644 --- a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: 步驟 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/chinese-traditional/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index fb95444e5edb5b..00000000000000 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: 第 14 步 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 2803cda0ec189f..04368a9f50d5b3 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: 步骤15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index fcf7ec703d2564..d219ffd233d912 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: 步骤 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index a14ede788659b3..0acee19ec87ef0 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Step 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 79faedb9483000..e7e2afe30c5e78 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: 步骤 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 983dce2d00ede0..062b5d5518ea0c 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: 步骤 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index c4e0d424c68685..41ec6728c793ca 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: 步骤 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 926403ff042837..be8b63d7311442 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: 步骤21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 76b0927a4f6628..0b29e3d5a88339 100644 --- a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: 步骤 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/chinese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index ef4eaead7008d3..00000000000000 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Paso 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index f4bc9b0f6b1746..bb5ef8c6dff03a 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: Paso 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index b8f546c074c5bf..c9b48cfe580f1c 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: Paso 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 44c17673daaad6..24ecdbdaa71d36 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Paso 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 7e3cd6f34498e6..1e3a7c8adb6fda 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: Paso 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 54a904e4684ce8..a18e13f087201a 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: Paso 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 55fd0b9f7b5554..56078a5b3917bf 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: Paso 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 40a88e5866784e..33671a33aff708 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: Paso 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 99ff3fb480de04..91667b8005593c 100644 --- a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: Paso 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/espanol/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 1d7230139877bf..00000000000000 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Schritt 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index e0e3d9c7a181c3..5c36e418093d2c 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: Schritt 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 25b217595c37ce..60618f14188cf9 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: Schritt 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 9dabc6ca807baf..5a9cef11807bd4 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Schritt 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 078ff04f4ce185..ec156ba554e113 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: Schritt 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 8174e1639b6878..e2110371291598 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: Schritt 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index fdf9508a090e0a..9eee1ce42ec3d4 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: Schritt 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 23ad4590a19812..070c1e764e695f 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: Schritt 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 27eb18d01ecd72..dd7f4ace4be18e 100644 --- a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: Schritt 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/german/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index 29c5ed17c79f31..1686002066d7f0 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -7,11 +7,11 @@ dashedName: step-1 # --description-- -In this project, you are going to learn about list comprehensions in Python by building a program that can take a `camelCase` or `PascalCase` formatted string and convert that to a `snake_case` formatted string. +In this project, you are going to learn about list comprehensions in Python by building a program that converts a `camelCase` or `PascalCase` formatted string into a `snake_case` formatted string. -List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster. +List comprehensions in Python offer a concise way of constructing lists without using loops or the `.append()` method, often resulting in a briefer and faster execution. -Start defining a new function named `convert_to_snake_case()` that accepts a string named `pascal_or_camel_cased_string` as input. For now, add a `pass` statement inside the function. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to temporarily fill the function body. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md index d10997857d8770..e68ba396532d44 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md @@ -1,15 +1,15 @@ --- id: 657ed53c19461d4b95c4757a -title: Passo 2 +title: Step 2 challengeType: 20 dashedName: step-2 --- # --description-- -Now create a new list named `snake_cased_char_list` inside the function. You can use a set of empty square braces to create the new list. +You need to add an empty list that will hold the characters of the string after you have converted them to snake case. -This list will hold the characters of the string after you have converted them to snake case. +Inside the function, replace the `pass` statement by creating an empty list named `snake_cased_char_list`. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index df97ce81d0d808..4fcd769a2bb521 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -7,9 +7,9 @@ dashedName: step-3 # --description-- -Now that you have an empty list in place, you can start iterating through the input string and start converting each character to snake case. +With the empty list in place, now you can start iterating through the input string and convert it into snake case. -Use a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char` which is short for character. For now, add a `pass` statement in the loop body. +Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement as a placeholder in the loop body. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md index 3cff64a584bed8..bafc0d16102af0 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md @@ -7,9 +7,11 @@ dashedName: step-4 # --description-- -Uppercase characters in camel case or pascal case indicate the start of new words. +In both camel case and pascal case, uppercase characters mark the beginning of new words. To convert the input string to snake case, you will need to check if the characters in the input string are uppercase. -Inside the loop body, use an `if` statement in conjunction with the `.isupper()` string method to check for uppercase characters and move `pass` inside the new `if` statement. +You can use the `.isupper()` string method to check if a character is uppercase. This method returns `True` if the character is uppercase and `False` if it is not. + +Inside the `for` loop, add an `if` statement to check if the current character is uppercase. Move the `pass` statement inside the new `if` statement. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index 9ec8a005e962e0..a2e70f734922c6 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -9,13 +9,7 @@ dashedName: step-5 Inside the `if` statement body, you need to convert any uppercase character to lowercase and prepend an underscore to this lowercase character. -Use the `.lower()` string method to convert uppercase characters to lowercase characters. You can then concatenate an underscore to the character using the plus sign. - -```python -'_' + char.lower() -``` - -Assign the modified character to a variable named `converted_character` inside the if statement body. +Use the `.lower()` string method to convert uppercase characters to lowercase characters. Then, prepend an underscore to the character. Assign the results to a variable named `converted_character`. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md index e9a0ec849903e6..35959690a674b3 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md @@ -7,13 +7,11 @@ dashedName: step-6 # --description-- -Still within the `if` statement body, use the `.append()` list method to add the converted character to the list you created earlier. +Within the `if` statement body, you are going to add the converted character to the list you created earlier. -```py -snake_cased_char_list.append(converted_character) -``` +For this, the `.append()` method will be used. This method adds a given object to the end of the list it is invoked on. -The `.append()` method adds a given object to the end of the list you invoke it on. +Use the `.append()` method on the `snake_cased_char_list` to add the `converted_character` to the list. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md index 72b2f5dd928c80..8959a55a4e812c 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md @@ -7,7 +7,9 @@ dashedName: step-7 # --description-- -Add an `else` clause on the same level as the existing `if` statement, inside the `for` loop. Add characters that are already in lowercase to the list of converted characters inside the body of the `else` clause. +You need to handle the characters that are already in lowercase by adding them to the list of converted characters. + +Right after the `if` statement within the `for` loop, add an `else` clause and use the `.append()` method to add `char` to the `snake_cased_char_list` variable. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index c2568eaacd0e83..45cc6ad2c0a1bd 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -7,13 +7,18 @@ dashedName: step-8 # --description-- -By the end of the loop, `snake_cased_char_list` should contain all the converted characters in correct order. Use the `.join()` string method to convert the list of characters into a string. +By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you can utilize the `.join()` method. + +The `join` method works by concatenating each element of a list into a string, separated by a designated string, known as the separator. ```py -''.join(snake_cased_char_list) +result_string = ''.join(characters) ``` -This joins the characters from the list to the empty string on which you called the `.join()` method. Save the result in a variable named `snake_cased_string` on the same level as the `snake_cased_char_list` variable. +The example above joins together the elements of the `characters` list into a single string where each element is concatenated together using an empty string as the separator. + +Now, right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. + # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 7c4f0407797781..ea8f1bb8fb3d65 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -7,15 +7,19 @@ dashedName: step-9 # --description-- -Strings in pascal case start with a capital character. Since you've converted all such characters to lowercase and prepended an underscore to them, chances are, the converted snake case string has a dangling underscode at the start. +In pascal case, strings begin with a capital letter. After converting all the characters to lowercase and adding an underscore to them, there's a chance of having an extra underscore at the start of your string. -The easiest way to strip such unwanted character is by using the `.strip()` string method and passing an underscore to the method as argument. +The easiest way to fix this is by using the `.strip()` string method, which removes from a string any leading or trailing characters among a set of characters passed as its argument. For example: ```py -snake_cased_string.strip('_') +original_string = "_example_string_" + +clean_string = original_string.strip('_') ``` -Make sure to save the resulting string in a variable named `clean_snake_cased_string` on the same level as the `snake_cased_string` variable. +The `strip()` method is applied to `original_string`. This removes any leading and trailing underscore. The result of the example above would be the string `'example_string'`. + +Declare a new variable named `clean_snake_cased_string` and assign it the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method. # --hints-- @@ -48,6 +52,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): snake_cased_char_list.append(char) --fcc-editable-region-- snake_cased_string = ''.join(snake_cased_char_list) - --fcc-editable-region-- ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md index fad85c2ce7f465..bd1b81cc11a2d7 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md @@ -1,13 +1,16 @@ --- id: 657f01ae9aea647b27402d3e -title: Passo 10 +title: Step 10 challengeType: 20 dashedName: step-10 --- # --description-- -Now all that is left to complete this function is to return the `clean_snake_cased_string` from the function. So, go ahead and return the string by adding a `return` statement on the same level as the `clean_snake_cased_string` variable. +To wrap up the function, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. + +Add a `return` statement at the end of the function to return the `clean_snake_cased_string`. + # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md index 518c95dab2725b..5168903a03cc56 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md @@ -7,7 +7,9 @@ dashedName: step-11 # --description-- -Since the function is now complete, put it to use inside another function. Create a new function called `main()` on the same level as the `convert_to_snake_case()` function. +With the function complete, you can now use it inside another function. + +Create a new function called `main()` with `pass` as the body of the function. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index 9a2367edf232fe..4fe34c9b8520f0 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -7,7 +7,9 @@ dashedName: step-12 # --description-- -Inside the `main()` function, replace `pass` with a `convert_to_snake_case()` call. Pass the string `'aLongAndComplexString'` as input to the function and print out the output using the `print()` function. +Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input. + +To display the output, pass the function call as the argument to the `print()` function. # --hints-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 56843f81edb8b7..cd0c3961ae2edf 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -7,21 +7,22 @@ dashedName: step-13 # --description-- -Before running the `main()` function, you need to make sure that the file is running as a script. Add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`. +In order to display the output of the `convert_to_snake_case()` function, you need to call the `main()` function. -Remember to use `pass` to fill the `if` statement body. +At the same level as the two existing functions, add a call to the `main()` function. You should see the given camel or pascal cased string converted to snake case upon execution. # --hints-- -You should write a `if` clause to check whether `__name__ == '__main__'` evaluates to `True` or not. Don't forget the colon at the end and use `pass` to fill the `if` body. +You should add a call to the `main()` function. ```js ({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\nif\s+__name__\s*==\s*("|')__main__\1\s*:/); - } -}) + test: () => { + const pythonCode = `_Node(_code.replace('\\\\r', '')).has_call("main()")`; + const result = runPython(pythonCode); + assert(result); + } +}); ``` # --seed-- diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 9f2f989cb63d4b..00000000000000 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Step 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index ce7ae1877b9273..45ba700555040e 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -1,8 +1,8 @@ --- id: 657f425dbab54e11993c80f0 -title: Passo 15 +title: Step 14 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- @@ -51,7 +51,6 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 9c054d264db869..10047b0fe727f3 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -1,15 +1,13 @@ --- id: 657f4345abe7f2161f99f1ad -title: Step 16 +title: Step 15 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- -Start by replacing `pass` with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list but do not put anything between the braces. - -Put the braces in separate lines so that you have some space between them, where you can work on the code for the list comprehension. +Replace the `pass` keyword with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list. # --hints-- @@ -53,6 +51,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index f1f2ed52b224e5..afaab8a276f46f 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -1,34 +1,28 @@ --- id: 657f43d341a0dd17120cdb08 -title: Passaggio 17 +title: Step 16 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- -Inside the space you left between the pair of square braces, you can describe the value that you would like to include in the list based on a given condition. +You will need to convert uppercase characters to lowercase and add an underscore before them. -```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() -] -``` - -Python will interpret this expression as "append `'_' + char.lower()` to the list if `char` is in uppercase" and this will convert the case for the capital letters in the input string. +Before proceeding to work on the list comprehension, you're going to give your function a return value. In this way you'll be able to check the output. -Start by adding this line within the square braces. +Use the `return` statement to return the list `snake_cased_char_list` from your function. # --hints-- -You should add `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should return the `snake_cased_char_list` list. Ensure the indentation is set correctly. ```js const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*\]/); +assert.match(function_body, /return\s*snake_cased_char_list/); ``` # --seed-- @@ -49,17 +43,13 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string + snake_cased_char_list = [] --fcc-editable-region-- - snake_cased_char_list = [ - ] --fcc-editable-region-- - - def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 0d05561ca52fc2..62edf28daef9ed 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -1,35 +1,56 @@ --- id: 657f456223b8c1187b461987 -title: Step 18 +title: Step 19 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- -When you start a list comprehension with an `if` statement like this, Python requires you to also add an `else` clause to the expression. +A list comprehension is a concise way to create lists in Python. A basic list comprehension consists of an expression followed by a `for` clause: ```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char -] +spam = [i * 2 for i in iterable] ``` -Python will interpret this updated expression as "append `'_' + char.lower()` to the list if `char` is in uppercase, append `char` as is otherwise" and this covers the case for both the capital and lowercase letters in the input string. +The above uses the variable `i` to iterate over `iterable`. Each elements of the resulting list is obtained by evaluating the expression `i * 2` at the current iteration. -Add an `else` clause inside the pair of square braces. +In this step, you need to fill the empty list `snake_cased_char_list` using the list comprehension syntax. + +Turn your empty list into a list comprehension that converts each character in `pascal_or_camel_cased_string` into a lowercase character and prepends an underscore to it (the code you commented out before may help you write the expression). Use `char` to iterate over `pascal_or_camel_cased_string`. # --hints-- -You should add `else char` after `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should turn `snake_cased_char_list` into a list comprehension that iterates over `pascal_or_camel_cased_string`. ```js -const transformedCode = code.replace(/\r/g, ""); -const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); -const { function_body } = convert_to_snake_case; +({ + test: () => assert(runPython(` + iters = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_iters() + len(iters) == 1 and iters[0].is_equivalent("pascal_or_camel_cased_string") + `)) +}) +``` + +Your list comprehension should use `char` to iterate over `pascal_or_camel_cased_string`. -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s+char\s*\]/); +```js +({ + test: () => assert(runPython(` + targets = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_targets() + len(targets) == 1 and targets[0].is_equivalent("char") + `)) +}) +``` + +Your list comprehension should evaluate `'_' + char.lower()` for each `char` in `pascal_or_camel_cased_string`. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower()") + `)) +}) ``` # --seed-- @@ -51,17 +72,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - - ] + snake_cased_char_list = [] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 2b3e2dfd1af666..a30bf0c9b05dab 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -1,41 +1,32 @@ --- id: 657f465f8e718b19c5105ae5 -title: Passo 19 +title: Step 20 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- -The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon. - -In this case, you need to iterate upon all the characters of the string. +List comprehensions accept conditional statements, to evaluate the provided expression only if certain conditions are met: ```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string -] +spam = [i * 2 for i in iterable if i > 0] ``` -And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. +As you can see from the output, the list of characters generated from `pascal_or_camel_cased_string` has been joined. Since the expression inside the list comprehension is evaluated for each character, the result is a lowercase string with all the characters separated by an underscore. -Add this last line of code to iterate over the characters of the string in your list comprehension and make sure that you're writing it within the pair of square braces. +Follow the example above to add an `if` clause to your list comprehension so that the expression is executed only if the character is uppercase. # --hints-- -You should add `for char in pascal_or_camel_cased_string` after `else char` within the square braces of `snake_cased_char_list`. +You should add an `if` clause with the condition `char.isupper()` to your list comprehension. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; - - assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*'_'\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s*char\s*for\s+char\s+in\s+pascal_or_camel_cased_string\s*\]/); - } +({ + test: () => assert(runPython(` + ifs = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_ifs() + len(ifs) == 1 and ifs[0].is_equivalent("char.isupper()") + `)) }) ``` @@ -58,18 +49,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - - ] + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index d159feeb1f4ff9..fea2df988fe71d 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -1,33 +1,31 @@ --- id: 657f47b12c51e41b3149e584 -title: Step 20 +title: Step 21 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- -You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, let's see a shorter alternative. +Still, the final result is not exactly what you want to achieve. You need to execute a different expression for the characters filtered out by the `if` clause. You'll use an `else` clause for that: ```py -return ''.join(snake_cased_char_list).strip('_') +spam = [i * 2 if i > 0 else -1 for i in iterable] ``` -This single line of code will join the list of characters into a string, strip off any dangling underscores, and return the resulting string. Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function. +Note that, differently from the `if` clause, the `if`/`else` construct must be placed between the expression and the `for` keyword. + +Modify your list comprehension so that when a character is not uppercase it remains unchanged. # --hints-- -You should return `''.join(snake_cased_char_list).strip('_')` at the end of `convert_to_snake_case()` function. +You should modify your list comprehension to evaluate the expression `'_' + char.lower()` if `char.isupper()` and char otherwise. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; - - assert.match(function_body, / +return\s+('|")\1\.join\(\s*snake_cased_char_list\s*\)\.strip\(\s*("|')_\2\s*\)/); - } +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower() if char.isupper() else char") + `)) }) ``` @@ -50,19 +48,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string - ] - + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string if char.isupper()] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 7af56e5bc90c44..445e22198e0785 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -1,8 +1,8 @@ --- id: 657f4a4a5828a01de04b652f -title: Step 21 +title: Step 22 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- @@ -19,7 +19,7 @@ You should not have any commented line of code in the `convert_to_snake_case()` const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; - + assert.equal(function_body.split("#").length - 1, 0); } }) @@ -56,6 +56,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 7e79d4d2696831..aa2269460297e3 100644 --- a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -1,8 +1,8 @@ --- id: 657f4add33ea4b1f61ba3dc8 -title: Step 22 +title: Step 23 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- @@ -48,11 +48,10 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) - + --fcc-editable-region-- -if __name__ == '__main__': - main() +main() ``` # --solutions-- @@ -71,8 +70,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('IAmAPascalCasedString')) - - -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/italian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 9af4cc8c5cf16d..00000000000000 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: ステップ 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 25212cde6fb2bd..2208e9cee8dc0e 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: ステップ 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index f740019c1b34bb..e00cabb03f2e9a 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: ステップ 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 181b9835db6fe5..4a0da9ae7377b1 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: ステップ 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 09c6b249a6c51e..ff1ff301263ad5 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: ステップ 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index d6fa68e805bf31..04bf99655cef21 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: ステップ 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index a009fb4b0f611c..73963b0ec73523 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: ステップ 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 2ffae73f2dd477..26a0e5cced5691 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: ステップ 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 2c4f5e5aae0811..8f57f5604a64a0 100644 --- a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: ステップ 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/japanese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 9f2f989cb63d4b..00000000000000 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Step 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index ad4cbe41f6c985..c0b5b1997daee1 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: Step 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 9c054d264db869..bda1296deb1fc9 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: Step 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index a14ede788659b3..0acee19ec87ef0 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Step 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 0d05561ca52fc2..40d6aa94297b51 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: Step 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index de00f494a786eb..edf2fa3c19b1e6 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: Step 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index d159feeb1f4ff9..dce8f5f68d8fc3 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: Step 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 7af56e5bc90c44..1ae8c2aecad0fd 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: Step 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index 7e79d4d2696831..921322c2a2d93a 100644 --- a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: Step 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/korean/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md index f862e3f4156409..1686002066d7f0 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657e928716b77b2277980276.md @@ -1,17 +1,17 @@ --- id: 657e928716b77b2277980276 -title: 1° passo +title: Step 1 challengeType: 20 dashedName: step-1 --- # --description-- -In this project, you are going to learn about list comprehensions in Python by building a program that can take a `camelCase` or `PascalCase` formatted string and convert that to a `snake_case` formatted string. +In this project, you are going to learn about list comprehensions in Python by building a program that converts a `camelCase` or `PascalCase` formatted string into a `snake_case` formatted string. -List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster. +List comprehensions in Python offer a concise way of constructing lists without using loops or the `.append()` method, often resulting in a briefer and faster execution. -Start defining a new function named `convert_to_snake_case()` that accepts a string named `pascal_or_camel_cased_string` as input. For now, add a `pass` statement inside the function. +To begin, define a new function named `convert_to_snake_case()` that takes `pascal_or_camel_cased_string` as input. Within the function body, include a `pass` statement to temporarily fill the function body. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md index d10997857d8770..e68ba396532d44 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ed53c19461d4b95c4757a.md @@ -1,15 +1,15 @@ --- id: 657ed53c19461d4b95c4757a -title: Passo 2 +title: Step 2 challengeType: 20 dashedName: step-2 --- # --description-- -Now create a new list named `snake_cased_char_list` inside the function. You can use a set of empty square braces to create the new list. +You need to add an empty list that will hold the characters of the string after you have converted them to snake case. -This list will hold the characters of the string after you have converted them to snake case. +Inside the function, replace the `pass` statement by creating an empty list named `snake_cased_char_list`. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md index 15bc4f591928d0..4fcd769a2bb521 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ee28cefc4945568287673.md @@ -1,15 +1,15 @@ --- id: 657ee28cefc4945568287673 -title: Passo 3 +title: Step 3 challengeType: 20 dashedName: step-3 --- # --description-- -Now that you have an empty list in place, you can start iterating through the input string and start converting each character to snake case. +With the empty list in place, now you can start iterating through the input string and convert it into snake case. -Use a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char` which is short for character. For now, add a `pass` statement in the loop body. +Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement as a placeholder in the loop body. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md index 8a52d8439c8bc2..bafc0d16102af0 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md @@ -1,15 +1,17 @@ --- id: 657ef2a86d4e545cec9a85fb -title: Passo 4 +title: Step 4 challengeType: 20 dashedName: step-4 --- # --description-- -Uppercase characters in camel case or pascal case indicate the start of new words. +In both camel case and pascal case, uppercase characters mark the beginning of new words. To convert the input string to snake case, you will need to check if the characters in the input string are uppercase. -Inside the loop body, use an `if` statement in conjunction with the `.isupper()` string method to check for uppercase characters and move `pass` inside the new `if` statement. +You can use the `.isupper()` string method to check if a character is uppercase. This method returns `True` if the character is uppercase and `False` if it is not. + +Inside the `for` loop, add an `if` statement to check if the current character is uppercase. Move the `pass` statement inside the new `if` statement. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md index a1ffd2aa2edd05..a2e70f734922c6 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efa642593c5746acc5c81.md @@ -1,6 +1,6 @@ --- id: 657efa642593c5746acc5c81 -title: Passo 5 +title: Step 5 challengeType: 20 dashedName: step-5 --- @@ -9,13 +9,7 @@ dashedName: step-5 Inside the `if` statement body, you need to convert any uppercase character to lowercase and prepend an underscore to this lowercase character. -Use the `.lower()` string method to convert uppercase characters to lowercase characters. You can then concatenate an underscore to the character using the plus sign. - -```python -'_' + char.lower() -``` - -Assign the modified character to a variable named `converted_character` inside the if statement body. +Use the `.lower()` string method to convert uppercase characters to lowercase characters. Then, prepend an underscore to the character. Assign the results to a variable named `converted_character`. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md index f50809627f0f96..35959690a674b3 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md @@ -1,19 +1,17 @@ --- id: 657efce98e958b75df86b305 -title: 6° passo +title: Step 6 challengeType: 20 dashedName: step-6 --- # --description-- -Still within the `if` statement body, use the `.append()` list method to add the converted character to the list you created earlier. +Within the `if` statement body, you are going to add the converted character to the list you created earlier. -```py -snake_cased_char_list.append(converted_character) -``` +For this, the `.append()` method will be used. This method adds a given object to the end of the list it is invoked on. -The `.append()` method adds a given object to the end of the list you invoke it on. +Use the `.append()` method on the `snake_cased_char_list` to add the `converted_character` to the list. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md index 3c997eba37c78d..8959a55a4e812c 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657efdcf7fe23b76c0cff9ec.md @@ -1,13 +1,15 @@ --- id: 657efdcf7fe23b76c0cff9ec -title: 7° passo +title: Step 7 challengeType: 20 dashedName: step-7 --- # --description-- -Add an `else` clause on the same level as the existing `if` statement, inside the `for` loop. Add characters that are already in lowercase to the list of converted characters inside the body of the `else` clause. +You need to handle the characters that are already in lowercase by adding them to the list of converted characters. + +Right after the `if` statement within the `for` loop, add an `else` clause and use the `.append()` method to add `char` to the `snake_cased_char_list` variable. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md index 40ee3ae7597468..45cc6ad2c0a1bd 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657effaa2a5e0277d71f9cbe.md @@ -1,19 +1,24 @@ --- id: 657effaa2a5e0277d71f9cbe -title: 8° passo +title: Step 8 challengeType: 20 dashedName: step-8 --- # --description-- -By the end of the loop, `snake_cased_char_list` should contain all the converted characters in correct order. Use the `.join()` string method to convert the list of characters into a string. +By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you can utilize the `.join()` method. + +The `join` method works by concatenating each element of a list into a string, separated by a designated string, known as the separator. ```py -''.join(snake_cased_char_list) +result_string = ''.join(characters) ``` -This joins the characters from the list to the empty string on which you called the `.join()` method. Save the result in a variable named `snake_cased_string` on the same level as the `snake_cased_char_list` variable. +The example above joins together the elements of the `characters` list into a single string where each element is concatenated together using an empty string as the separator. + +Now, right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`. + # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md index 42e9bbff53d690..ea8f1bb8fb3d65 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0044be09db790b1eb1c5.md @@ -1,21 +1,25 @@ --- id: 657f0044be09db790b1eb1c5 -title: 9° passo +title: Step 9 challengeType: 20 dashedName: step-9 --- # --description-- -Strings in pascal case start with a capital character. Since you've converted all such characters to lowercase and prepended an underscore to them, chances are, the converted snake case string has a dangling underscode at the start. +In pascal case, strings begin with a capital letter. After converting all the characters to lowercase and adding an underscore to them, there's a chance of having an extra underscore at the start of your string. -The easiest way to strip such unwanted character is by using the `.strip()` string method and passing an underscore to the method as argument. +The easiest way to fix this is by using the `.strip()` string method, which removes from a string any leading or trailing characters among a set of characters passed as its argument. For example: ```py -snake_cased_string.strip('_') +original_string = "_example_string_" + +clean_string = original_string.strip('_') ``` -Make sure to save the resulting string in a variable named `clean_snake_cased_string` on the same level as the `snake_cased_string` variable. +The `strip()` method is applied to `original_string`. This removes any leading and trailing underscore. The result of the example above would be the string `'example_string'`. + +Declare a new variable named `clean_snake_cased_string` and assign it the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method. # --hints-- @@ -48,6 +52,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): snake_cased_char_list.append(char) --fcc-editable-region-- snake_cased_string = ''.join(snake_cased_char_list) - --fcc-editable-region-- ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md index fad85c2ce7f465..bd1b81cc11a2d7 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f01ae9aea647b27402d3e.md @@ -1,13 +1,16 @@ --- id: 657f01ae9aea647b27402d3e -title: Passo 10 +title: Step 10 challengeType: 20 dashedName: step-10 --- # --description-- -Now all that is left to complete this function is to return the `clean_snake_cased_string` from the function. So, go ahead and return the string by adding a `return` statement on the same level as the `clean_snake_cased_string` variable. +To wrap up the function, return the `clean_snake_cased_string`. This will complete the function and allow you to use it to convert strings from pascal or camel case to snake case. + +Add a `return` statement at the end of the function to return the `clean_snake_cased_string`. + # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md index fd52d3d2ebdb1d..5168903a03cc56 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f025ec86c3d7c4177b6be.md @@ -1,13 +1,15 @@ --- id: 657f025ec86c3d7c4177b6be -title: Passo 10 +title: Step 11 challengeType: 20 dashedName: step-11 --- # --description-- -Since the function is now complete, put it to use inside another function. Create a new function called `main()` on the same level as the `convert_to_snake_case()` function. +With the function complete, you can now use it inside another function. + +Create a new function called `main()` with `pass` as the body of the function. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md index cc59f878abb497..4fe34c9b8520f0 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f0353c9523d7d896873ea.md @@ -1,13 +1,15 @@ --- id: 657f0353c9523d7d896873ea -title: Etapa 12 +title: Step 12 challengeType: 20 dashedName: step-12 --- # --description-- -Inside the `main()` function, replace `pass` with a `convert_to_snake_case()` call. Pass the string `'aLongAndComplexString'` as input to the function and print out the output using the `print()` function. +Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input. + +To display the output, pass the function call as the argument to the `print()` function. # --hints-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md index 46d69e57eac1d7..cd0c3961ae2edf 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f04ed0035f47ed04d0f1f.md @@ -1,27 +1,28 @@ --- id: 657f04ed0035f47ed04d0f1f -title: Etapa 13 +title: Step 13 challengeType: 20 dashedName: step-13 --- # --description-- -Before running the `main()` function, you need to make sure that the file is running as a script. Add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`. +In order to display the output of the `convert_to_snake_case()` function, you need to call the `main()` function. -Remember to use `pass` to fill the `if` statement body. +At the same level as the two existing functions, add a call to the `main()` function. You should see the given camel or pascal cased string converted to snake case upon execution. # --hints-- -You should write a `if` clause to check whether `__name__ == '__main__'` evaluates to `True` or not. Don't forget the colon at the end and use `pass` to fill the `if` body. +You should add a call to the `main()` function. ```js ({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\nif\s+__name__\s*==\s*("|')__main__\1\s*:/); - } -}) + test: () => { + const pythonCode = `_Node(_code.replace('\\\\r', '')).has_call("main()")`; + const result = runPython(pythonCode); + assert(result); + } +}); ``` # --seed-- diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index fb340ec28aefd2..00000000000000 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Passo 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index ce7ae1877b9273..45ba700555040e 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -1,8 +1,8 @@ --- id: 657f425dbab54e11993c80f0 -title: Passo 15 +title: Step 14 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- @@ -51,7 +51,6 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index b1098e06eb5933..10047b0fe727f3 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -1,15 +1,13 @@ --- id: 657f4345abe7f2161f99f1ad -title: Passo 16 +title: Step 15 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- -Start by replacing `pass` with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list but do not put anything between the braces. - -Put the braces in separate lines so that you have some space between them, where you can work on the code for the list comprehension. +Replace the `pass` keyword with the variable `snake_cased_char_list` and assign it an empty list. Use the square brace notation to create the list. # --hints-- @@ -53,6 +51,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index eabf31d4334377..afaab8a276f46f 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -1,34 +1,28 @@ --- id: 657f43d341a0dd17120cdb08 -title: Passo 17 +title: Step 16 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- -Inside the space you left between the pair of square braces, you can describe the value that you would like to include in the list based on a given condition. +You will need to convert uppercase characters to lowercase and add an underscore before them. -```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() -] -``` - -Python will interpret this expression as "append `'_' + char.lower()` to the list if `char` is in uppercase" and this will convert the case for the capital letters in the input string. +Before proceeding to work on the list comprehension, you're going to give your function a return value. In this way you'll be able to check the output. -Start by adding this line within the square braces. +Use the `return` statement to return the list `snake_cased_char_list` from your function. # --hints-- -You should add `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should return the `snake_cased_char_list` list. Ensure the indentation is set correctly. ```js const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*\]/); +assert.match(function_body, /return\s*snake_cased_char_list/); ``` # --seed-- @@ -49,17 +43,13 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string + snake_cased_char_list = [] --fcc-editable-region-- - snake_cased_char_list = [ - ] --fcc-editable-region-- - - def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 8ef65f88380c4e..62edf28daef9ed 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -1,35 +1,56 @@ --- id: 657f456223b8c1187b461987 -title: Passo 18 +title: Step 19 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- -When you start a list comprehension with an `if` statement like this, Python requires you to also add an `else` clause to the expression. +A list comprehension is a concise way to create lists in Python. A basic list comprehension consists of an expression followed by a `for` clause: ```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char -] +spam = [i * 2 for i in iterable] ``` -Python will interpret this updated expression as "append `'_' + char.lower()` to the list if `char` is in uppercase, append `char` as is otherwise" and this covers the case for both the capital and lowercase letters in the input string. +The above uses the variable `i` to iterate over `iterable`. Each elements of the resulting list is obtained by evaluating the expression `i * 2` at the current iteration. -Add an `else` clause inside the pair of square braces. +In this step, you need to fill the empty list `snake_cased_char_list` using the list comprehension syntax. + +Turn your empty list into a list comprehension that converts each character in `pascal_or_camel_cased_string` into a lowercase character and prepends an underscore to it (the code you commented out before may help you write the expression). Use `char` to iterate over `pascal_or_camel_cased_string`. # --hints-- -You should add `else char` after `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`. +You should turn `snake_cased_char_list` into a list comprehension that iterates over `pascal_or_camel_cased_string`. ```js -const transformedCode = code.replace(/\r/g, ""); -const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); -const { function_body } = convert_to_snake_case; +({ + test: () => assert(runPython(` + iters = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_iters() + len(iters) == 1 and iters[0].is_equivalent("pascal_or_camel_cased_string") + `)) +}) +``` + +Your list comprehension should use `char` to iterate over `pascal_or_camel_cased_string`. -assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s+char\s*\]/); +```js +({ + test: () => assert(runPython(` + targets = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_targets() + len(targets) == 1 and targets[0].is_equivalent("char") + `)) +}) +``` + +Your list comprehension should evaluate `'_' + char.lower()` for each `char` in `pascal_or_camel_cased_string`. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower()") + `)) +}) ``` # --seed-- @@ -51,17 +72,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - - ] + snake_cased_char_list = [] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index d375c14ff605cf..a30bf0c9b05dab 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -1,41 +1,32 @@ --- id: 657f465f8e718b19c5105ae5 -title: 19° passo +title: Step 20 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- -The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon. - -In this case, you need to iterate upon all the characters of the string. +List comprehensions accept conditional statements, to evaluate the provided expression only if certain conditions are met: ```py -snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string -] +spam = [i * 2 for i in iterable if i > 0] ``` -And there you have it. These three lines of code do the same task as the `for` loop you worked on previously while being cleaner and somewhat faster. +As you can see from the output, the list of characters generated from `pascal_or_camel_cased_string` has been joined. Since the expression inside the list comprehension is evaluated for each character, the result is a lowercase string with all the characters separated by an underscore. -Add this last line of code to iterate over the characters of the string in your list comprehension and make sure that you're writing it within the pair of square braces. +Follow the example above to add an `if` clause to your list comprehension so that the expression is executed only if the character is uppercase. # --hints-- -You should add `for char in pascal_or_camel_cased_string` after `else char` within the square braces of `snake_cased_char_list`. +You should add an `if` clause with the condition `char.isupper()` to your list comprehension. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; - - assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*'_'\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s*char\s*for\s+char\s+in\s+pascal_or_camel_cased_string\s*\]/); - } +({ + test: () => assert(runPython(` + ifs = _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_ifs() + len(ifs) == 1 and ifs[0].is_equivalent("char.isupper()") + `)) }) ``` @@ -58,18 +49,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - - ] + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 195e5352acab8d..fea2df988fe71d 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -1,33 +1,31 @@ --- id: 657f47b12c51e41b3149e584 -title: 20° passo +title: Step 21 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- -You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, let's see a shorter alternative. +Still, the final result is not exactly what you want to achieve. You need to execute a different expression for the characters filtered out by the `if` clause. You'll use an `else` clause for that: ```py -return ''.join(snake_cased_char_list).strip('_') +spam = [i * 2 if i > 0 else -1 for i in iterable] ``` -This single line of code will join the list of characters into a string, strip off any dangling underscores, and return the resulting string. Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function. +Note that, differently from the `if` clause, the `if`/`else` construct must be placed between the expression and the `for` keyword. + +Modify your list comprehension so that when a character is not uppercase it remains unchanged. # --hints-- -You should return `''.join(snake_cased_char_list).strip('_')` at the end of `convert_to_snake_case()` function. +You should modify your list comprehension to evaluate the expression `'_' + char.lower()` if `char.isupper()` and char otherwise. ```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); - const { function_body } = convert_to_snake_case; - - assert.match(function_body, / +return\s+('|")\1\.join\(\s*snake_cased_char_list\s*\)\.strip\(\s*("|')_\2\s*\)/); - } +({ + test: () => assert(runPython(` + _Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower() if char.isupper() else char") + `)) }) ``` @@ -50,19 +48,12 @@ def convert_to_snake_case(pascal_or_camel_cased_string): # return clean_snake_cased_string --fcc-editable-region-- - snake_cased_char_list = [ - '_' + char.lower() if char.isupper() - else char - for char in pascal_or_camel_cased_string - ] - + snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string if char.isupper()] --fcc-editable-region-- - - + return ''.join(snake_cased_char_list).strip('_') def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index e16d853bafd6ed..445e22198e0785 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -1,8 +1,8 @@ --- id: 657f4a4a5828a01de04b652f -title: Passo 21 +title: Step 22 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- @@ -19,7 +19,7 @@ You should not have any commented line of code in the `convert_to_snake_case()` const transformedCode = code.replace(/\r/g, ""); const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); const { function_body } = convert_to_snake_case; - + assert.equal(function_body.split("#").length - 1, 0); } }) @@ -56,6 +56,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index e0545f99fd4040..aa2269460297e3 100644 --- a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -1,8 +1,8 @@ --- id: 657f4add33ea4b1f61ba3dc8 -title: Passo 22 +title: Step 23 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- @@ -11,7 +11,7 @@ Finally try out this new implementation by executing the program. Change the inp If you've done everything correctly, you should see the input string converted into snake case, like before. -Parabéns! Now your `convert_to_snake_case()` function is ready. +Congratulations! Now your `convert_to_snake_case()` function is ready. # --hints-- @@ -48,11 +48,10 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('aLongAndComplexString')) - + --fcc-editable-region-- -if __name__ == '__main__': - main() +main() ``` # --solutions-- @@ -71,8 +70,5 @@ def convert_to_snake_case(pascal_or_camel_cased_string): def main(): print(convert_to_snake_case('IAmAPascalCasedString')) - - -if __name__ == '__main__': - main() +main() ``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/portuguese/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 03d060d7971d7d..00000000000000 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Hatua ya 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution. - -# --hints-- - -You should add a call to `main()` inside the `if` statement. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -You should not have `pass` in your `if` statement. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index e0d736c25dc920..c72cbfcf65a4e4 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: Hatua ya 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index d2ffe833b418f4..6e4c11031a4df7 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: Hatua ya 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index d199013b623178..e9fa553777e61b 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Hatua ya 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 3dfd0bc2430a9a..0775d8daa20c5b 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: Hatua ya 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 1531354effac4d..df05f3b4549a95 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: Hatua ya 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 83203b17aa4f61..7a7eb4a2276756 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: Hatua ya 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index ba95bcb639e3e4..66dd17872f1f9d 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: Hatua ya 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index b5bc63c55db4c2..4c522257f7437d 100644 --- a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: Hatua ya 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/swahili/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md deleted file mode 100644 index 243a3b630b3753..00000000000000 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f28a0482132aca51a9212.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -id: 657f28a0482132aca51a9212 -title: Крок 14 -challengeType: 20 -dashedName: step-14 ---- - -# --description-- - -Замініть `pass` на виклик функції `main()` в межах тіла інструкції `if`. Ви маєте побачити, що наданий рядок у верблюдячому регістрі або регістрі Паскаля перетворений на рядок в зміїному регістрі. - -# --hints-- - -Додайте виклик `main()` до інструкції `if`. - -```js -({ - test: () => { - const transformedCode = code.replace(/\r/g, ""); - assert.match(transformedCode, /\n +main\s*\(\s*\)/); - } -}) -``` - -Інструкція `if` не повинна містити `pass`. - -```js -({ - test: () => { - const commentless_code = __helpers.python.removeComments(code); - const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/); - - assert.notMatch(block_body, /pass/); - } -}) -``` - -# --seed-- - -## --seed-contents-- - -```py -def convert_to_snake_case(pascal_or_camel_cased_string): - snake_cased_char_list = [] - for char in pascal_or_camel_cased_string: - if char.isupper(): - converted_character = '_' + char.lower() - snake_cased_char_list.append(converted_character) - else: - snake_cased_char_list.append(char) - snake_cased_string = ''.join(snake_cased_char_list) - clean_snake_cased_string = snake_cased_string.strip('_') - - return clean_snake_cased_string - -def main(): - print(convert_to_snake_case('aLongAndComplexString')) - ---fcc-editable-region-- -if __name__ == '__main__': - pass ---fcc-editable-region-- -``` diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md index 32170739f5e7a1..4c4ec04b50dc3e 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f425dbab54e11993c80f0.md @@ -2,7 +2,7 @@ id: 657f425dbab54e11993c80f0 title: Крок 15 challengeType: 20 -dashedName: step-15 +dashedName: step-14 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md index 05da7606b7da52..48f7018a777fbf 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4345abe7f2161f99f1ad.md @@ -2,7 +2,7 @@ id: 657f4345abe7f2161f99f1ad title: Крок 16 challengeType: 20 -dashedName: step-16 +dashedName: step-15 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md index 60dbc5f170f530..5c6557632194ed 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f43d341a0dd17120cdb08.md @@ -2,7 +2,7 @@ id: 657f43d341a0dd17120cdb08 title: Крок 17 challengeType: 20 -dashedName: step-17 +dashedName: step-16 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md index 49d526ab5bfd4c..2e7a16802ccadd 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f456223b8c1187b461987.md @@ -2,7 +2,7 @@ id: 657f456223b8c1187b461987 title: Крок 18 challengeType: 20 -dashedName: step-18 +dashedName: step-19 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md index 72e848cc5ab7eb..f10bc6b576f178 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f465f8e718b19c5105ae5.md @@ -2,7 +2,7 @@ id: 657f465f8e718b19c5105ae5 title: Крок 19 challengeType: 20 -dashedName: step-19 +dashedName: step-20 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md index 4fb5702393478e..6e9a78852d73b4 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md @@ -2,7 +2,7 @@ id: 657f47b12c51e41b3149e584 title: Крок 20 challengeType: 20 -dashedName: step-20 +dashedName: step-21 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md index 5957f048984f75..c65205bff0a1ce 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4a4a5828a01de04b652f.md @@ -2,7 +2,7 @@ id: 657f4a4a5828a01de04b652f title: Крок 21 challengeType: 20 -dashedName: step-21 +dashedName: step-22 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md index fef9d9e3577b53..e00fc62ac736d8 100644 --- a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/657f4add33ea4b1f61ba3dc8.md @@ -2,7 +2,7 @@ id: 657f4add33ea4b1f61ba3dc8 title: Крок 22 challengeType: 20 -dashedName: step-22 +dashedName: step-23 --- # --description-- diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md new file mode 100644 index 00000000000000..4c3596601b944c --- /dev/null +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b10c10a4c0a0e095137ee.md @@ -0,0 +1,53 @@ +--- +id: 663b10c10a4c0a0e095137ee +title: Step 17 +challengeType: 20 +dashedName: step-17 +--- + +# --description-- + +Instead of returning the list `snake_cased_char_list`, you will need to join its elements into a single string using an empty string `''` as the separator. + +Modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string as a separator. + +# --hints-- + +You should modify the `return` statement to return the result of joining `snake_cased_char_list` with an empty string `''` as the separator using the `join()` method. + +```js +({ + test: () => assert(runPython(` + _Node(_code).find_function('convert_to_snake_case').find_return().is_equivalent('return "".join(snake_cased_char_list)') + `)) +}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return snake_cased_char_list +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +``` diff --git a/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md new file mode 100644 index 00000000000000..7b535b7fd106f7 --- /dev/null +++ b/curriculum/challenges/ukrainian/07-scientific-computing-with-python/learn-list-comprehension-by-building-a-case-converter-program/663b16e62fee463b4caf46e9.md @@ -0,0 +1,62 @@ +--- +id: 663b16e62fee463b4caf46e9 +title: Step 18 +challengeType: 20 +dashedName: step-18 +--- + +# --description-- + +After joining the elements of the list `snake_cased_char_list`, you will need to remove any leading or trailing underscores from the resulting string. For this, use the `strip` method with the underscore character `_` as an argument. + +Method calls can be chained together, which means that the result of one method call can be used as the object for another method call. + +```py +words_list = ['hello', 'world', 'this', 'is', 'chained', 'methods'] +result = ' '.join(words_list).upper() +``` + +In the example above, the `.upper()` method is chained to `' '.join(words_list)`, therefore `.upper()` is called on the result of the `.join()` call. + +Modify the `return` statement by chaining to `''.join(snake_cased_char_list)` a call to the `.strip()` method to remove any leading or trailing underscores. + +# --hints-- + +You should modify the return statement to include the `strip` method with the underscore character `_` as an argument. + +```js +const transformedCode = code.replace(/\r/g, ""); +const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case"); +const { function_body } = convert_to_snake_case; + +assert.match(function_body, /return\s*''.join\(snake_cased_char_list\).strip\('_'\)/); +``` + +# --seed-- + +## --seed-contents-- + +```py +def convert_to_snake_case(pascal_or_camel_cased_string): + # snake_cased_char_list = [] + # for char in pascal_or_camel_cased_string: + # if char.isupper(): + # converted_character = '_' + char.lower() + # snake_cased_char_list.append(converted_character) + # else: + # snake_cased_char_list.append(char) + # snake_cased_string = ''.join(snake_cased_char_list) + # clean_snake_cased_string = snake_cased_string.strip('_') + + # return clean_snake_cased_string + + snake_cased_char_list = [] +--fcc-editable-region-- + return ''.join(snake_cased_char_list) +--fcc-editable-region-- + +def main(): + print(convert_to_snake_case('aLongAndComplexString')) + +main() +```