title: How to run a function for each row in a nested list?
body: <p>I'm a Python newbie and trying to write code that checks if a nested list has a valid set of numbers. Each row and each column have to be valid. I have written a function called check_sequence which validates if a list has a valid set of numbers. How would I call that function from another to check to see if the row is valid? So for example, I need something like this for check_rows:</p>
  
  <pre><code>check_sequence(list):
    checks if list is valid
  
  check_rows(list):
    For each of the rows in the nested list call check_sequence
  </code></pre>
  
  <p>Here is my code for check_sequence:</p>
  
  <pre><code>def check_sequence(mylist):
      pos = 0
      sequence_counter = 1
      while pos &lt; len(mylist):
          print "The pos is: " + " " + str(pos)
          print "The sequence_counter is:" + " " + str(sequence_counter)
          for number in mylist:
              print "The number is:" + " " + str(number)
              if number == sequence_counter:
                  sequence_counter = sequence_counter + 1
                  pos = pos + 1
                  break
              else:
                  # if list is at the last position on the last item
                  if sequence_counter not in mylist:
                      print "The pos is:" + " " + str(pos) + " and the last position is:"  + " "  + str(mylist[len(mylist) - 1])
                      print "False"
                      return False
      print "True"
      return True
  </code></pre>
  
  <p>So I'd call the main method like below:</p>
  
  <pre><code>check_square([[1, 2, 3],
             [2, 3, 1],
             [3, 1, 2]])
  
  def check_square(list):
     if check_rows() and check_columns() == True:
         return True
     else:
         return False
  </code></pre>