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

Tell us what’s happening:

I am not sure what exactly the step they want me to input in this scenario can someone help me in this

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

You’re halfway there.

Going back to the example code, you need to add the expression to be applied, which goes before the “for”.

spam = [i * 2 for i in iterable]

The expression here is to convert each character in the pascal_or_camel_cased_string into a lowercase character and prepend with an underscore.

Add that in, if you have further problems post your code with 3 backticks before and after into the forum post without the brackets
(```)

(```)

Hey Punit, try this for your list comprehension:

python

CopyEdit

SOLUTION REMOVED BY MODERATOR

Also, make sure your return line is closed properly and everything is indented correctly inside the main() function.

It is against the forum rules to give the answers. Although your text had other code as well not asked in the question it also included the answer. We guide the posters so they can work out the answer for themselves.

so should i add spam = [i * 2 for i in iterable] in the code?

no, you need to use the example to add the correct code, do not copy the example exactly

got it thanks for the information