Splitting Strings 2 issue

Hi everyone. I am confused with my code output for the splitting strings II exercise.

In this screenshot, I successfully completed the first step and created a list of the author names. I used a loop for the second step to split each name into first and last names. I assigned these to the variable split_author_names. I printed it out to test and it looks right. I have a list of the first and last names separated by commas.

My idea was that since the names only contain first and last names, the last names will be at the odd indices. I tested this by the print statement: print(split_author_names[1]). This successfully printed the first last name, Lorde.

I then used another for loop to iterate through the odd indices starting at 1, going until the length of split_author_names by 2. The list it creates is the last names in the right order, but for some reason, each individual letter has been split into its own string. I do not know why this is happening.

The problem seems to be that split_author_names[i] is a string, not a list.
So you are trying to a a list + a string (so Python tries to turn the string into a list when adding it to another list).

One way to fix this is to put the string as an additional element of the list:


Another way is to put the string into a list and then add it to the other list:

  author_last_names += [split_author_names[i]]
1 Like

Thanks for the reply! I understand now really appreciate it