<p>这有点棘手,但主要思想是在到达<code>\</code>时复制到目前为止的选项,并跟踪其中的两个选项,请看以下内容:</p>
<pre><code>m_str = ['someone can tell/figure',
'a/the squeaky wheel gets the grease/oil',
'accounts for (someone or something)',
'that\'s/there\'s (something/someone) for you']
lines = [[]]
for line in m_str:
options = [[]]
for word in line.split(" "):
if "/" in word:
new_options = []
for option in options:
new_options.append(option + [word.split("/")[0]])
new_options.append(option + [word.split("/")[1]])
options = new_options
# print(new_options)
# options = [m_func(options, item) for item in options]
else:
for option in options:
option.append(word)
lines.append(options)
print(lines[1:])
</code></pre>
<p>输出:</p>
<pre><code>[[['someone', 'can', 'tell'], ['someone', 'can', 'figure']], [['a', 'squeaky', 'wheel', 'gets', 'the', 'grease'], ['a', 'squeaky', 'wheel', 'gets', 'the', 'oil'], ['the', 'squeaky', 'wheel', 'gets', 'the', 'grease'], ['the', 'squeaky', 'wheel', 'gets', 'the', 'oil']], [['accounts', 'for', '(someone', 'or', 'something)']], [["that's", '(something', 'for', 'you'], ["that's", 'someone)', 'for', 'you'], ["there's", '(something', 'for', 'you'], ["there's", 'someone)', 'for', 'you']]]
</code></pre>