title: Python: Dictionary to Spare Vector
body: <p>I am new to Python and programming in general. I was working on Pyschool exercises Topic 8, Q 11 on converting Dictionary to Spare Vectore. </p>
  
  <p>I was asked to Write a function that converts a dictionary back to its sparese vector representation.</p>
  
  <p>Examples</p>
  
  <pre><code>&gt;&gt;&gt; convertDictionary({0: 1, 3: 2, 7: 3, 12: 4})
  [1, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 4]
  &gt;&gt;&gt; convertDictionary({0: 1, 2: 1, 4: 2, 6: 1, 9: 1})
  [1, 0, 1, 0, 2, 0, 1, 0, 0, 1]
  &gt;&gt;&gt; convertDictionary({})
  []
  </code></pre>
  
  <p>I have attempted many times. Below is the latest code I have:</p>
  
  <pre><code>def convertDictionary(dictionary):
      k=dictionary.keys()
      v=dictionary.values()
      result=[]
      for i in range(0,max(k)):
          result.append(0)
          for j in k:
              result[j]=v[k.index(j)]
      return result
  </code></pre>
  
  <p>The returned error is:</p>
  
  <pre><code>Traceback (most recent call last):
  File "Code", line 8, in convertDictionary
  IndexError: list assignment index out of range
  </code></pre>
  
  <p>Could anyone help me? Thank you so much!</p>