human
K Centers Problem | Set 1 ( Greedy Approximate Algorithm ) | Python3 program for the above approach.
index of city having the maximum distance to it 's  closest center.
updating the distance of the cities to their closest centers.
updating the index of the city with the maximum distance to it 's closest center.
Printing the maximum distance of a city to a center that is our answer print ( ).
Printing the cities that were chosen to be made centers.
Driver Code.
Function Call"
How can the above be solved in Python?

Give me a code to k Centers Problem and the other steps required?
assistant
#Here is code to k Centers Problem and the other steps required.
 def maxindex ( dist , n ) :
	mi = 0
	for i in range ( n ) :
		if ( dist [ i ] > dist [ mi ] ) :
			mi = i
	return mi
def selectKcities ( n , weights , k ) :
	dist = [ 0 ] * n
	centers = [ ]
	for i in range ( n ) :
		dist [ i ] = 10 ** 9
	max = 0
	for i in range ( k ) :
		centers . append ( max )
		for j in range ( n ) :
			dist [ j ] = min ( dist [ j ] , weights [ max ] [ j ] )
		max = maxindex ( dist , n )
	print ( dist [ max ] )
	for i in centers :
		print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	n = 4
	weights = [ [ 0 , 4 , 8 , 5 ] , [ 4 , 0 , 10 , 7 ] , [ 8 , 10 , 0 , 9 ] , [ 5 , 7 , 9 , 0 ] ]
	k = 2
	selectKcities ( n , weights , k )