If you look at the documentation for the
Remove the item at the given position in the list, and return it. If no index is specified,
a.pop() removes and returns the last item in the list.
x = [1, 4, 6, 8, 34]
y = x.pop()
print(y) # 34
print(x) # [1, 4, 6, 8]
# The popped/removed element is returned by the pop method.
# The original array is mutated.
One line assuming you split
author_last_names = [name.split(' ')[-1] for name in author_names]
I used both .split() and .pop() in a function to accomplish this task, I took advantage of the returning property of .pop() to store the last name. This is the function:
for author in authors:
splitted_author = author.split(" ")
last_name = splitted_author.pop()
Hey man, thank you so much. This was quite helpful
this was the first problem I ever got stuck while learning python. it was very confusing!