title: Python: setting negative values in list to 0
body: <p>This seems like it would be simple, but I am having an issue with setting negative numbers in a list to 0. Here is my code:</p>
  
  <pre><code>def subtract_lists(list1, list2):
      list3 = list()
      for i in range(0,len(list1)):
              list3.append(list1[i]-list2[i])
      if i &lt; 0:
              i = 0
      else:
              i = i
      return list3
  </code></pre>
  
  <p>I am using this function when making stacked bar charts with matplotlib. Essentially, some values in list2 are larger than values in list1. For the data I have it doesn't make sense to have negative values. Essentially anything with a negative value would just plot as one solid bar.</p>
  
  <p>EDIT: Just wanted to add that the top of the graph is list3.</p>
  
  <p>EDIT 2: Thank you everyone for the help. I ended up using this due to the simplicity:</p>
  
  <pre><code>def subtract_lists(list1, list2):
      list3 = list()
      for i in range(0,len(list1)):
              list3.append(max(list1[i]-list2[i], 0))
      return list3
  </code></pre>
  
  <p>However I appreciate all the solutions and help, I am going to try some of the other examples just for a learning experience. </p>