title: Python: Average of items in matrix
body: <p>We have a code like this at our school as a home assignment. The code need to be done in python 2, because of an school made app:</p>
  <p>Write a function average(m), which receives a matrix containing integer items as argument. The function calculates and returns the average of the items in the matrix.</p>
  <p>Below is the code given:</p>
  <pre><code>def test():
      l = []
      for i in range(random.randint(3,5)):
          ll = []
          for j in range(random.randint(3,4)):
              ll.append(random.randint(1,10))
          l.append(ll)
      print (&quot;Matrix:&quot;,l)
      print (&quot;Average of items:&quot;, average(l))
  
  test()
  print (&quot;&quot;)
  test()
  
  import random
  </code></pre>
  <p>I tried doing this:</p>
  <pre><code>def average(m):
  
  lst = []
  average = sum(lst) / len(lst)
   return average
  </code></pre>
  <p>But it comes back with:</p>
  <pre><code>TypeError: unsupported operand type(s) for /: 'list' and 'int'
  </code></pre>
  <p>I've tried to find solutions for making lists join another, but I have not been able to make any use of the help that is provided in the web. Appreciate any help that is given, thank you.</p>