How can I improve my code?

So I got stuck on this, everytime i ran my code using 2 different methods, both of which appear above as working solutions, but both gave me errors.

Couldn’t figure it out so I looked at the codecademy solution which is this:

authors = "Audre Lorde,Gabriela Mistral,Jean Toomer,An Qi,Walt Whitman,Shel Silverstein,Carmen Boullosa,Kamala Suraiyya,Langston Hughes,Adrienne Rich,Nikki Giovanni"

author_names = authors.split(',')


author_last_names = []
for name in author_names:

You will notice that Codecademy have removed the name William Carlos Williams from the original list entirely, I don’t know why because if you add it back in the code still works.

Any thoughts on this?

any changes you still have these two approaches that didn’t work and can you share them?

could be a simple mismatch between starting code and solution code

I have exactly the same thing as you and I’m not getting errors, so presumably this was a simple mismatch with the solution code, as stetim94 suggested, and has since been fixed.

Separately, this made me realize I could use a list comprehension for this one that produces the same thing:

author_last_names2 = [i.split()[-1] for i in author_names]

I was surprised that the i.split()[-1] bit worked, that you could call an element at a specific index for a list that is only temporarily generated by i.split() during the iteration