回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对Python和编程还不熟悉。我在做Pyschool练习第8题第11题关于将字典转换为备用向量机。在</p>
<p>我被要求写一个函数,将字典转换回它的sparese向量表示。在</p>
<p>示例</p>
<pre><code>>>> convertDictionary({0: 1, 3: 2, 7: 3, 12: 4})
[1, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 4]
>>> convertDictionary({0: 1, 2: 1, 4: 2, 6: 1, 9: 1})
[1, 0, 1, 0, 2, 0, 1, 0, 0, 1]
>>> convertDictionary({})
[]
</code></pre>
<p>我试过很多次。以下是我的最新代码:</p>
^{pr2}$
<p>返回的错误是:</p>
<pre><code>Traceback (most recent call last):
File "Code", line 8, in convertDictionary
IndexError: list assignment index out of range
</code></pre>
<p>有人能帮我吗?非常感谢你!在</p>