def isGraphicSequence(seq):
      """
       Assumes that the degreeSequence is a list of non negative integers
       http://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Gallai_theorem
      """
      # Check to ensure there are an even number of odd degrees
      if sum(seq)%2 != 0: return False
      # Erdos-Gallai theorem
      for k in range(1, len(seq)+1):
        leftSum = sum(seq[:(k)])
        rightSum = k * (k-1) + sum([min(x, k) for x in seq[k:]])
        if leftSum > rightSum: return False
      return True

       Assumes that the degreeSequence is a list of non negative integers
       http://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Gallai_theorem
      
recipes/Python/579141_Simple_Graph_library/recipe-579141.py