<p>将问题归结为基本要素。
下面的问题应该是可行的,但是你的问题看起来很像家庭作业</p>
<pre class="lang-py prettyprint-override"><code> text = "test this for an example" # use a text phrase to test.
words = user_input.split(). # space is default for split.
print(" ".join(reversed(words))) # reverse list, and print as string.
</code></pre>
<p>结果:</p>
<pre><code>example an for this test
</code></pre>
<p>如果你需要过滤数字</p>
<pre class="lang-py prettyprint-override"><code> text = "test this for an 600 example" # use a text phrase to test.
words = text.split() # space is default for split.
print(" ".join(reversed([wd for wd in words if not wd.isnumeric()])))
# filter, reverse, and print as string.
</code></pre>
<p>结果:</p>
<pre><code>example an for this test
</code></pre>
<p>如果您需要拒绝函数中少于4个单词的数字/响应</p>
<pre class="lang-py prettyprint-override"><code>def homework(text: str) -> bool:
words = text.split()
composed = list(reversed([wd for wd in words if not wd.isnumeric()]))
result = len(words) == len(composed) and len(words) > 3
if result:
print(' '.join(composed))
return result
</code></pre>