Splitting a hashtag into words
Write code · Challenge · §10.2 Filling a one-dimensional table
Hashtags join words without spaces, and tag does not include the # sign. Complete the function solution, which returns the number of ways to cut the hashtag tag into pieces so that every piece is a word in the word list words and no letters are left over from the start to the end.
The same word may be used more than once. Two ways are different if they cut at different positions. A word listed more than once in words still counts as one word. If the whole tag is one word, not cutting it is also one way. If tag cannot be cut this way, return 0.
Function
solution(tag, words)
Constraints
tagis a string of lowercase English letters, with a length from 1 to 100.- The length of
wordsis from 1 to 50. - Each word in
wordsis a string of lowercase English letters, with a length from 1 to 10. - The answer can be a very large number. Return it as a Python integer as it is, without taking a remainder.
Examples
| tag | words | result |
|---|---|---|
'dailylook' | ['dai', 'ly', 'daily', 'lo', 'ok', 'look'] | 4 |
'catvlog' | ['cat', 'vlog', 'ca', 'tv', 'log'] | 2 |
Starter code
def solution(tag, words):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.