Back to Freecodecamp

Step 16

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

latest1.4 KB
Original Source

--description--

You will need to convert uppercase characters to lowercase and add an underscore before them.

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.

Use the return statement to return the list snake_cased_char_list from your function.

--hints--

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

--fcc-editable-region--

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

main()