title: list initialization VS list clear in python
body: <p>Actually I wrote a code to find a character from the list and print the index but am not getting the difference between these two codes please help me out:</p>
  
  <pre><code>#My list:
  l = ["MA-%78*%%1","MA%-78*%1","MA%%-%78*1","M%A#-78*%%1"]
  
  search(l,"%")
  </code></pre>
  
  <p>Code 1:</p>
  
  <pre><code>def search(string_list,search_character):
      sl = string_list
      char1 = search_character
      l1 = list()
      l11 = list()
      for j in range(len(string_list)):
          l1.clear()
          s1 = string_list[j]
          for i in range(len(s1)):
              if s1[i] == search_character:
                  l1.append(i+1)
          l11.append(l1)
      return l11
  </code></pre>
  
  <p>This yields the output:<br>
  <code>[[1, 8, 9], [1, 8, 9], [1, 8, 9], [1, 8, 9]]</code></p>
  
  <p>Code 2:</p>
  
  <pre><code>def search(string_list,search_character):
      sl = string_list
      char1 = search_character
      l11 = list()
      for j in range(len(string_list)):
          l1 = list()
          s1 = string_list[j]
          for i in range(len(s1)):
              if s1[i] == search_character:
                  l1.append(i+1)
          l11.append(l1)
      return l11
  </code></pre>
  
  <p>I get correct output when I initialized the list again without clearing it:<br>
   <code>[[4, 8, 9], [3, 8], [3, 4, 6], [2, 9, 10]]</code></p>
  
  <p>I didn't understood what is wrong with <code>l1.clear()</code> function. </p>