Back to Freecodecamp

Step 15

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

latest1.3 KB
Original Source

--description--

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--

You should declare an empty list named snake_cased_char_list within convert_to_snake_case.

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, /clean_snake_cased_string\s+    snake_cased_char_list\s*=\s*\[\n*\s*\n*\]/);
    }
})

--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
--fcc-editable-region--
    pass


--fcc-editable-region--

def main():
    print(convert_to_snake_case('aLongAndComplexString'))

main()