curriculum/challenges/english/blocks/learn-list-comprehension-by-building-a-case-converter-program/657f47b12c51e41b3149e584.md
Still, the final result is not exactly what you want to achieve. You need to execute a different expression for the characters filtered out by the if clause. You'll use an else clause for that:
spam = [i * 2 if i > 0 else -1 for i in iterable]
Note that, differently from the if clause, the if/else construct must be placed between the expression and the for keyword.
Modify your list comprehension so that when a character is not uppercase it remains unchanged.
You should modify your list comprehension to evaluate the expression '_' + char.lower() if char.isupper() and char otherwise.
({
test: () => assert(runPython(`
_Node(_code).find_function("convert_to_snake_case").find_variable("snake_cased_char_list").find_comp_expr().is_equivalent("'_' + char.lower() if char.isupper() else char")
`))
})
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--
snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string if char.isupper()]
--fcc-editable-region--
return ''.join(snake_cased_char_list).strip('_')
def main():
print(convert_to_snake_case('aLongAndComplexString'))
main()