title: Keyerror : 1 python
body: <p>I am trying to write a k means algorithm and at very basic stage right now.<br>
  The code is as follows to randomly select the centres for clustering:</p>
  
  <pre><code>import numpy as np
  
  import random
  
  X = [2,3,5,8,12,15,18]
  
  C = 2
  
  def rand_center(ip,C):
  
      centers = {}
      for i in range (C):
          if i&gt;0:
              while centers[i] != centers[i-1]:   
                  centers[i] = random.choice(X)
                  else:
              centers[i] = random.choice(X)   
      return centers
      print (centers)
  
  rand_center(X,C)
  </code></pre>
  
  <p>When I run this, it gives me KeyError:1<br>
  Can anyone guide me resolve this error? </p>