Step-by-step explanation of this short for loop, please


I was wondering if some kind soul could explain me what exactly is happening, step-by-step or some similar kind of explanation, in the for loop in the following code:

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:

After not succeeding in completing this exercise by myself I was forced to ask for a solution, but even then I was not able to fully understand this for loop.

Thank you very much.

1 Like

if that is what you are after, why not use tools which allow us to step through our code:

we loop over the author names, split these names in first and last name and then append the last name to a new list


Oh, I didn’t even know this beautiful thing existed. Thank you so much for the link provided sir, I’m definitely going to use it!

1 Like