How to select only last names?

see this topic:

How to ask good questions (and get good answers)

it even features that searching for answers first is a good idea.

What does [-1] do? Well, we can access elements in a list by index, by using negative values, we can access elements from the right hand side. So -1 is the last item of a list, -2 the second to last item of the list and so forth

3 Likes

Could someone remind me where we can find explanation in previous lessons that says we can write methods “.split” and index "[-1] in the same line like here: some_str.split()[-1]? Because i don’t really remember anything like that. But i do remember that there was about different methods in one line, but not indexes.
Also another solution to the second part of this exercise is by list comprehension:

author_last_names = [full_name.split()[-1] for full_name in author_names]

If i am not mistaken.

I’m having trouble finding any reference for using an index after str.split() on the internet.
I don’t doubt that it exists or think the, “how to”, is wrong.

I wrote this function to solve the problem:

def find_last_name(author_names):
author_last_names =
for name in author_names:
last = name.split()
author_last_names.append(last[-1])
return author_last_names