def is_threshold_sequence(degree_sequence):
 ds = degree_sequence[:]
 ds.sort()
 while ds:
  if (ds[0] == 0):
   ds.pop(0)
   continue
  if (ds[(-1)] != (len(ds) - 1)):
   return False
  ds.pop()
  ds = [(d - 1) for d in ds]
 return True

def is_threshold_sequence ( degree_sequence ) : ds = degree_sequence [ : ] ds . sort ( ) while ds : if ( ds [ 0 ] == 0 ) : ds . pop ( 0 ) continue if ( ds [ ( - 1 ) ] != ( len ( ds ) - 1 ) ) : return False ds . pop ( ) ds = [ ( d - 1 ) for d in ds ] return True
returns true if the sequence is a threshold degree seqeunce .