input: Write a function to implement a k-means clustering algorithm in Python. The function should take two parameters: k representing the number of clusters and data which is the dataset to be clustered. The function should return a tuple containing the cluster assignments for each data point and the final centroids of the clusters.
  
  assert kmeans(2, np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]]) == ([0, 1, 0, 1, 1, 1], np.array([[1, 1], [4, 3]]))
  assert kmeans(3, np.array([[1, 1], [2, 1], [4, 3], [5, 4], [9, 10], [10, 10]]) == ([0, 0, 1, 1, 2, 2], np.array([[1.5, 1], [4.5, 3.5], [9.5, 10]]))
  assert kmeans(1, np.array([[1, 2], [3, 4], [5, 6]]) == ([0, 0, 0], np.array([[3, 4]]))
  assert kmeans(2, np.array([]) == ([], np.array([]))
output: 
  def kmeans(k, data):
      if len(data) == 0:
          return ([], np.array([]))
      
      centroids = data[np.random.choice(data.shape[0], k, replace=False)]
      while True:
          distances = np.linalg.norm(data[:, np.newaxis] - centroids, axis=2)
          labels = np.argmin(distances, axis=1)
          new_centroids = np.array([data[labels == i].mean(axis=0) for i in range(k)])
          
          if np.all(centroids == new_centroids):
              break
          centroids = new_centroids
      
      return (labels, centroids)
  