human
Construct a graph from given degrees of all vertices | A function to print the adjacency matrix ..
n is number of vertices.
For each pair of vertex decrement the degree of both vertex ..
Print the result in specified form.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to construct a graph from given degrees of all vertices and the other steps required.
 def printMat ( degseq , n ) :
	mat = [ [ 0 ] * n for i in range ( n ) ]
	for i in range ( n ) :
		for j in range ( i + 1 , n ) :
			if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :
				degseq [ i ] -= 1
				degseq [ j ] -= 1
				mat [ i ] [ j ] = 1
				mat [ j ] [ i ] = 1
	print ( " ▁ " , end = " ▁ " )
	for i in range ( n ) :
		print ( " ▁ " , " ( " , i , " ) " , end = " " )
	print ( )
	print ( )
	for i in range ( n ) :
		print ( " ▁ " , " ( " , i , " ) " , end = " " )
		for j in range ( n ) :
			print ( " ▁ " , mat [ i ] [ j ] , end = " " )
		print ( )
if __name__ == ' _ _ main _ _ ' :
	degseq = [ 2 , 2 , 1 , 1 , 1 ]
	n = len ( degseq )
	printMat ( degseq , n )