input: Write a function to calculate the average of a list of numbers in Python. Given a list of integers or floats, the function should return the average value as a float. If the list is empty, the function should return 0.
  
  def avg_list(lst):
      if not lst:
          return 0
      sum = 0
      for i in lst:
          sum += i
      avg = sum / len(lst)
      return avg
  
  assert avg_list([1, 2, 3, 4, 5]) == 3.0
  assert avg_list([10, 20, 30, 40, 50]) == 30.0
  assert avg_list([-1, -2, -3, -4, -5]) == -3.0
  assert avg_list([0.5, 1.5, 2.5, 3.5]) == 2.0
  assert avg_list([]) == 0
output: def avg_list(lst):
      if not lst:
          return 0
      sum = 0
      for i in lst:
          sum += i
      avg = sum / len(lst)
      return avg