Back to Freecodecamp

Step 6

curriculum/challenges/english/blocks/learn-list-comprehension-by-building-a-case-converter-program/657efce98e958b75df86b305.md

latest1.1 KB
Original Source

--description--

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.

Use the .append() method on the snake_cased_char_list to add the converted_character to the list.

--hints--

You should use the .append() method to add the converted character to the snake_cased_char_list.

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\.append\s*\(\s*converted_character\s*\)/);
    }
})

--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:
--fcc-editable-region--
        if char.isupper():
            converted_character = '_' + char.lower()
--fcc-editable-region--