Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A pipeline has three stages. For the input "Hello, World", it should give ["hello", "world"], but it gives ["hello,", "world"]. Which stage is wrong? Say how you would find out, and fix it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Print the result of each stage.
hello, world: right.['hello,', 'world']: right (the comma is still stuck to the word, and removing it is the job of stage 3).['hello,', 'world'] in the original: wrong. It strips only the full stop, ".", and the word has a comma.So the bug is in stage 3: the marks to strip must include the comma. The fix is w.strip(".,"), or better a longer string of marks, ".,!?;:".
Answer: Stage 3. Strip the comma too: w.strip(".,").
Log in to join the discussion.
Loading…