How to select only last names?

I’m a new member here and I can’t find this question anywhere and you can’t send messages to mods either.

My question is, what do I need to do to start a new topic?

I don’t think there’s anything specific you need to do before that’s an option. It is however worthwhile following the tutorial with @discobot before adding a new thread. Bear in mind that a lot of the mods and almost all of the users here are either experienced volunteers who are generous with their time or fellow learners (by and large the majority of users fit this category). Please do check the following link beforehand as it details a lot of information that makes it easier for both you and any responders-

Hi! To find out what I can do, say @discobot display help.

for name in author_names:
  author_last_names.append(name[name.index(" ") + 1:])


I looked at the solution for the problem because I had figured there was probably a more elegant solution. Thankfully, I was right! This is what my original answer was. My thought process was to find the index of the " " or space in between the first name and last name and then add whatever was after that.

The problem with this, just like using [1] instead of [-1] in the solution is that if there was a middle name, it would add both the middle name and name to author_last_names.

I love coming into the forums to see explanations of the solutions or seeing other’s thought processes because it allows me to learn more than the lessons teach and I can reflect back on my own work! Good luck to anyone else learning or just brushing up on topics!

1 Like

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(’,’)

count = 0
for i in author_names:
lst = author_names[count].split()
count += 1

This was my solution. I added a comma to the end of the authors string.