Learn Python List Comprehension by Building a Case Converter Program - Step 19

Tell us what’s happening:

I’m on step 19 of the scientific computing with python course. The display is correct but not the code. I’ve used Ai extensively for at least an hour to try to figure out the problem but no luck. Help would be appreciated, thank you!!

Your code so far

def convert_to_snake_case(pascal_or_camel_cased_string):
    snake_cased_char_list = [
        '_' + char.lower() if char.isupper() else char
        for char in pascal_or_camel_cased_string
    ]
    snake_cased_string = ''.join(snake_cased_char_list)
    clean_snake_cased_string = snake_cased_string.strip('_')

# User Editable Region

    return clean_snake_cased_string


# User Editable Region

    return ''.join(snake_cased_char_list).strip('_')

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

main()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Learn Python List Comprehension by Building a Case Converter Program - Step 19

you should reset the step, and change only the line in the editable region, snake_cased_char_list = [], you need to create the list comprehension that does the listed things, not anything else, do not create other variables, do not change return statement do not remove commented out code

please reset the step and try again

I’m sorry, the input I provided was after I had tried a lot of stuff lol.

I did it exactly like you said a lot of times, but the code still won’t pass.I’ll put the code here

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 = ['_' + char.lower() if char.isupper() else char for char in pascal_or_camel_cased_string]
    return ''.join(snake_cased_char_list).strip('_')

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

main()

And the Output is perfect: “a_long_and_complex_string”

Thanks for your help.

it does not matter if the output is perfect, you need to follow the instructions

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 .

follow this, what you did does not exactly follow this

also that is not the output expected here, you are not asked to arrive to the final result right now