Why we should use [-1]

Hello, I would like to ask for a clarification. In this exercise, I don’t fully understand why we should use [-1], as name is not the last column. In fact, we also have hourly_wage and hours_worked.
Therefore, why should we have the following code: get_last_name = lambda x: x.split()[-1] ?
Could someone explain this to me?

get_last_name = lambda x: x.split(' ')[-1]

[-1] refers to the split, not the original column.
the result of “get_last_name” will be [‘Name’, ‘LastName’]. You can try to run this code without the [-1] portion and see.

In order to get only the last name from [‘Name’, ‘LastName’], we need to get the last item [-1], or simply [1]… as the last item is also the second item.
You can try them both and you will see the result is the same.

1 Like