title: How to optimize this python function?
body: <p>I new to python programming.How to optimize this code? It also gives an error UnboundLocalError: local variable 'list1' referenced before assignment.but if I define list1 outside the loop it takes too much time to execute for large lists.</p>
  
  <pre><code>def sum_pairs(ints, s):
      list2 = []
      for i in range(len(ints)):
          if i == len(ints) - 1:
              break
          for j in range(i + 1, len(ints)):
              if i != j and (ints[i] + ints[j] == s):
                  list1 = []
                  if list2 == []:
                      list1[0:2] = ints[i], ints[j]
                      list2[0:2] = i, j
                  elif list2[-1] &gt; j:
                      list1[0:2] = ints[i], ints[j]
                      list2[0:2] = i, j
  
                  break
       if list1 == []:
          return None
      return list1
  print(sum_pairs([10, 5, 2, 3, 7, 5], 10))
  </code></pre>
  
  <p>I am writing a function which returns the first two values (parse from the left please) in order of appearance that adds up to form the sum. for example:</p>
  
  <pre><code>  **sum_pairs([10, 5, 2, 3, 7, 5], 10)
   #                 ^-----------^   5 + 5 = 10, indices: 1, 5
   #                       ^--^      3 + 7 = 10, indices: 3, 4 *
   #  * entire pair is earlier, and therefore is the correct answer
   == [3, 7]**
  </code></pre>