title: Python Array with Dicts remove ‚Duplicates‘
body: <p>I have an array with dicts containing cookie information.
  Example:</p>
  <pre><code>[
      {'domain': '.scrapethissite.com', 'expiry': 1683192201, 'httpOnly': False, 'name': '_ga', 'path': '/', 'secure': False, 'value': 'GA1.2.880485616.1620120162'},
      {'domain': '.scrapethissite.com', 'expiry': 1620206605, 'httpOnly': False, 'name': '_gid', 'path': '/', 'secure': False, 'value': 'GA1.2.1342682571.1620120162'},
      {'domain': '.scrapethissite.com', 'expiry': 1627896207, 'httpOnly': False, 'name': '_fbp', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'fb.1.1620120161975.1281622715'},
      {'domain': '.scrapethissite.com', 'expiry': 1683192205, 'httpOnly': False, 'name': '_ga', 'path': '/', 'secure': False, 'value': 'GA1.2.880485616.1620120162'},
      {'domain': '.scrapethissite.com', 'expiry': 1620206609, 'httpOnly': False, 'name': '_gid', 'path': '/', 'secure': False, 'value': 'GA1.2.1342682571.1620120162'}
  ]
  </code></pre>
  <p>The problem is that I have some duplicates, it’s the same cookie but it has different expiry.
  Example: there are two <code>_gid</code> and <code>_ga</code> Cookies with different expiry dates.</p>
  <p>My goal is a function to remove duplicates by creating a result array that only contains every cookie once by adding each key/value “name” only once.</p>
  <pre class="lang-py prettyprint-override"><code>def cookie_remove_duplicates(array):
      # Array for results
      result_array = []
      # go thru array
      for i in range(0, len(array)):
          # Get Value for Key 'name' 
          tmp_value_unsorted = array[i].get('name')
          
          if(len(result_array) == 0):
              result_array.append(array[i])
          
          # Go thru results array
          for y in range(0, len(result_array)):
              tmp_value_sorted = result_array[y].get('name')
  
              
              # if value is not the same add to result array 
              if(tmp_value_sorted != tmp_value_unsorted):
                  result_array.append(array[i])
  </code></pre>
  <p>The function ends up in a endless loop. I don’t know that I am doing wrong, hope you can help.</p>
  <p>Thanks in advance,
  Andi</p>