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

Tell us what’s happening:

I am not sure if this is my code or something else as I’ve tried a few different things but whenever i try to use the .join() method it gives me an Attribute Error and says “object has no attribute ‘join’”. I tried to use .append() and that doesn’t give me the error but the code obviously won’t pass. What am I doing wrong here?

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 = []
    return snake_cased_char_list.join('', snake_cased_char_list)

# User Editable Region


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

main()

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

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

Lists in Python don’t have the join method. You might be thinking about join method from the str type.

This is the instructions I’ve been given here - I did try .append() but it said to use the join() method. Any further suggestions? Thank you so much!!

Please have a look at the commented code provided. In that see the last part, how “join” is used to form snake_cased_string, that will give you the clue.

1 Like

Great thank you I got it now! much appreciated!