md 原文如下
# 从小到大
nums = [1, 4, 5, 7, 3, 5, 9]
for i in range(0, len(nums)):
Min = {
"num": int(float('inf')),
"index": 0
}
for j in range(0, len(nums) - i):
if nums[j] < Min["num"]:
Min["num"] = nums[j]
Min["index"] = j
nums.pop(Min["index"])
nums.append(Min["num"])
for i in range(0, len(nums)):
print(nums[i])
vditor.getHtml()返回内容如下
`<pre><code class="language-python"># 从小到大\nnums = [1, 4, 5, 7, 3, 5, 9]\nfor i in range(0, len(nums)):\n Min = {\n "num": int(float('inf')),\n "index": 0\n }\n for j in range(0, len(nums) - i):\n if nums[j] < Min["num"]:\n Min["num"] = nums[j]\n Min["index"] = j\n nums.pop(Min["index"])\n nums.append(Min["num"])\nfor i in range(0, len(nums)):\n print(nums[i])\n\n</code></pre>\n`
我希望返回如下
<pre class="vditor-ir__preview" data-render="1"><div class="vditor-copy"><textarea></textarea><span aria-label="复制" onmouseover="this.setAttribute('aria-label', '复制')" class="vditor-tooltipped vditor-tooltipped__w" onclick="this.previousElementSibling.select();document.execCommand('copy');this.setAttribute('aria-label', '已复制')"><svg><use xlink:href="#vditor-icon-copy"></use></svg></span></div><code class="language-python hljs" style="max-height: 776px;"><span class="hljs-comment"># 从小到大</span>
nums = [<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">7</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">9</span>]
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(nums)):
Min = {
<span class="hljs-string">"num"</span>: <span class="hljs-built_in">int</span>(<span class="hljs-built_in">float</span>(<span class="hljs-string">'inf'</span>)),
<span class="hljs-string">"index"</span>: <span class="hljs-number">0</span>
}
<span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(nums) - i):
<span class="hljs-keyword">if</span> nums[j] < Min[<span class="hljs-string">"num"</span>]:
Min[<span class="hljs-string">"num"</span>] = nums[j]
Min[<span class="hljs-string">"index"</span>] = j
nums.pop(Min[<span class="hljs-string">"index"</span>])
nums.append(Min[<span class="hljs-string">"num"</span>])
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(nums)):
<span class="hljs-built_in">print</span>(nums[i])
</code></pre>
请问如何解决?
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于