Correct result but the program would not accept

I wasn’t able to code the solution the program wanted. I used this and the program did display the correct result but the program would not accept:

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


id	name	hourly_wage	hours_worked	get_last_name
0	10310	Lauren Durham	19	43	Durham
1	18656	Grace Sellers	17	40	Sellers

This is the result the program wanted, why break it up?

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

If you were coding for a personal project or work purposes, your solution would be perfectly fine!

However, the code lessons tend to go step by step, making the test cases behind it validate each step you take, not the final outcome.

I also got stuck in this lesson for longer that I anticipated, and at the end, the problem was the same you faced.

1 Like

Also ran into the same issue, however looking back i did not read the question correctly, and also did not pay attention to the message prompt at the bottom after running the script.

Now that I have seen the code here. It makes sense but as @dkirkeberg put it my result was correct before as well :innocent:. I guess with the lambda function as a seperate line we can later use it again on another data column.

What is the index -1 for? I used 1 instead and it worked the same. However if I completly skip it the resulting table looks like this:

	id	name	hourly_wage	hours_worked	last_name
0	10310	Lauren Durham	19	43	['Lauren', 'Durham']
1	18656	Grace Sellers	17	40	['Grace', 'Sellers']
2	61254	Shirley Rasmussen	16	30	['Shirley', 'Rasmussen']
3	16886	Brian Rojas	18	47	['Brian', 'Rojas']
4	89010	Samantha Mosley	11	38	['Samantha', 'Mosley']
5	87246	Louis Guzman	14	39	['Louis', 'Guzman']
6	20578	Denise Mcclure	15	40	['Denise', 'Mcclure']
7	12869	James Raymond	15	32	['James', 'Raymond']
8	53461	Noah Collier	18	35	['Noah', 'Collier']
9	14746	Donna Frederick	20	41	['Donna', 'Frederick']
10	71127	Shirley Beck	14	32	['Shirley', 'Beck']
11	92522	Christina Kelly	8	44	['Christina', 'Kelly']
12	22447	Brian Noble	11	39	['Brian', 'Noble']
13	61654	Randy Key	16	38	['Randy', 'Key']
14	16988	Diana Stewart	14	48	['Diana', 'Stewart'

I presume it wants it to be step by step, as @design8521863073 said previously.

It wants you to learn the concept so it wouldn’t accept a more complicated solution as the answer.