Hi i am stuck on this task
Step 19
In Python, a list comprehension is a construct that allows you to generate a new list by applying an expression to each item in an existing iterable and optionally filtering items with a condition. Apart from being briefer, list comprehensions often run faster.
A basic list comprehension consists of an expression followed by a for
clause:
Example Code
spam = [i * 2 for i in iterable]
The above uses the variable i
to iterate over iterable
. Each elements of the resulting list is obtained by evaluating the expression i * 2
at the current iteration.
In this step, you need to fill the empty list snake_cased_char_list
using the list comprehension syntax.
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
.
i did this but it dint accept
snake_cased_char_list =
snake_cased_char_list = [(‘_’ + char.lower()) if char.isupper() else char for char in pascal_or_camel_cased_string]
i dont know what to do to solve