title: Python: Functions - carry the results from one function into another
body: <p>i have two functions. The first function - def training_list() creates two lists - under_50k &amp; over_50k. I would like the second function def sums_lists() to create a sum_list which adds up each index within both lists and then appends each list to create 1 list - sums_list. when i run the code, it says over_50k is not defined in the sums_list function. Can you please tell me how i define this, i want to carry over the under_50k &amp; over_50k list into the new function</p>
  
  <hr>
  
  <ul>
  <li><p>error message</p>
  
  <p><code>File "C:\Python34\Lib\assign1.py", line 208, in sums_list over_50k_sum_list = [sum(k) for k in zip(*over_50k)] NameError: name 'over_50k' is not defined</code></p></li>
  </ul>
  
  <hr>
  
  <pre><code>def training_list():
  
      data_list = create_data(data_url)
      training_list = data_list[:int(len(data_list) * 75 / 100)]
      test_list = data_list[int(len(data_list) * 25 / 100):]
  
      #return training_list
  
  
      over_50k = []
      over_50k_count = 0
      under_50k = []
      under_50k_count = 0
  
      for row in training_list:
          if row[-1].lstrip() == '&lt;=50K':
              under_50k.append(row[:-1])
              under_50k_count +=1
          elif row [-1].lstrip() == "&gt;50K":
              over_50k.append(row[:-1])
              over_50k_count +=1
  
  
      return under_50k,over_50k
  
  def sums_list():
  
      over_50k_sum_list = []
      under_50k_sum_list = []
  
      over_50k_sum_list = [sum(k) for k in zip(*over_50k)]
      under_50k_sum_list = [sum(k) for k in zip(*under_50k)]
      sums_list = over_50k_sum_list + under_50k_sum_list
  
      print(sums_list)
      return sums_list
  
  def main():
      def trainging_list():
  
          over_50k = [[1, 2, 3, 4], [3, 4, 5, 6], [7, 8, 9, 8]]
          under_50k = [[1, 4, 6, 8], [3, 7, 4, 5], [6, 9, 4, 5]]
          print(over_50k)
          return over_50k, under_50k
  
      over_50k, under_50k = trainging_list()
  
      def sum_columns(over_50k, under_50k):
          print("a")
          over_50k_sum_list = [sum(k) for k in zip(*over_50k)]
          under_50k_sum_list = [sum(k) for k in zip(*under_50k)]
          sums = over_50k_sum_list + under_50k_sum_list
          print(sums)
          return sums
  main()
  </code></pre>