author_last_names = [name.strip().split()[-1] for name in authors.split(",")]
The primary sticking point in this discussion seems to be using [-1] to grab the last name, and more specifically why it’s grabbing a string of characters rather than the string’s last character.
First, we perform
>>> authors.split(",") ['Audre Lorde', ' William Carlos Williams', ' Gabriela Mistral', ' Jean Toomer', ' An Qi', ' Walt Whitman', ' Shel Silverstein', ' Carmen Boullosa', ' Kamala Suraiyya', ' Langston Hughes', ' Adrienne Rich', ' Nikki Giovanni']
This is the first step, which gives us a list of strings. We can index elements of a list as well as iterate over a list (which is our next objective).
(Breaking up the list comprehension for readability we have:)
for name in authors.split(","): name.strip().split()[-1]
At each pass of this loop, name becomes the next element of authors. Remember that a list can contain other lists, which is essentially what we have here. As we loop through our list of author names, name becomes the next full name string. Reading the for loop’s action from left to right, we are first doing
>>> name.strip() 'William Carlos Williams'
This removes leading and trailing whitespace (those spaces we identified next to the commas from earlier). Because name.strip() evaluates to ‘William Carlos Williams’ (on some pass), our next step essentially looks like
>>> 'William Carlos Williams'.split() ['William', 'Carlos', 'Williams']
which is a list of one author’s full name, and we want the last name (the last element of this list). We get that by index -1.
name.strip().split()[-1] evaluates to
‘William Carlos Williams’.split()[-1] evaluates to
[‘William’, ‘Carlos’, ‘Williams’][-1] evaluates to