Hello, I’m currently doing the Python Fundamentals course, in the data science path, and was trying to do different solutions for the Splitting Strings II lesson:
Can someone explain to me why this particular solution didn’t work out?
For some reason, when I try to add name[1]
to the last_author_names
list it adds every individual letter.
I think it has to do with your section where you are trying to append the last name. Currently you are just adding the first letter.
Try something more like where you are appending based on the negative index:
author_last_names.append(name[-1])
Did you check the solution to compare to your answer?
1 Like
Hi,
You want to use the append method, like so;
author_last_names.append(name[1])
+= would also work if you did;
author_last_names += [name[1]] ← putting it back into a list of one item
It’s because you’re effectively trying to add a string onto a list, python is trying to work it out best it can behind the scenes, and that’s the result.
2 Likes
Yes, that’s exactly what was happening, thanks!
2 Likes
The solution did use the append method, but I was trying to do it using +=
1 Like
I’m glad you could figure it out though! That’s what matters! Happy Coding!
1 Like