1def word_break(source, dictionary):
2 word_set = set(dictionary)
3 dp = [False] * (len(source) + 1)
4 dp[0] = True
5 for end in range(1, len(source) + 1):
6 for start in range(end):
7 if dp[start] and source[start:end] in word_set:
8 dp[end] = True
9 break
10 return dp[-1]