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

Tell us what’s happening:

How can I solve this problem? I used the .lower() and at the console it prints the correct string, without ‘_’ and everithing in lower case, what should I do? Thanks

Your code so far

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


# User Editable Region

    snake_cased_char_list = [char '_' + .lower() for char in pascal_or_camel_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/135.0.0.0 Safari/537.36

Challenge Information:

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

this is not correct syntax, don’t you see an error in the terminal?

Here it is the console return:

if you have an error like that code can’t work

I do not understand how you can print the correct string (you said so in the first post)

you need to fix the syntax error

Hi there,
I took a look at your code and noticed a small issue.

The console actually provides some really helpful hints:( Also, you did write the code, but I’m sharing this console output as something that usually appears before the code is written, just to give you some useful insight. So don’t get confused when seeing it. :blush: )

// running tests
1. You should turn snake_cased_char_list into a list comprehension that iterates over pascal_or_camel_cased_string.
2. Your list comprehension should use char to iterate over pascal_or_camel_cased_string.
3. Your list comprehension should evaluate '_' + char.lower() for each char in pascal_or_camel_cased_string.
// tests completed

If you go through these messages carefully, you’ll see that it’s expecting a specific structure for the list comprehension.

Notice anything? :eyes:
There’s just one small part at the beginning that doesn’t belong. You only need to remove that, and your code should work perfectly. You’re really close—just a quick fix away from passing all the tests. Keep it up!