title: How can I remove duplicates from a list of dataclass-objects which each have a list as a field?
body: <p>I have this code:</p>
  <pre><code>from dataclasses import dataclass
  from typing import List
  
  @dataclass(eq=True, frozen=True)
  class TestClass:
      field1: str
      field_list: List[str]
  
  duplicate_list = [TestClass(&quot;foo&quot;, [&quot;bar&quot;, &quot;cat&quot;]), TestClass(&quot;foo&quot;, [&quot;bar&quot;, &quot;cat&quot;]), TestClass(&quot;foo&quot;, [&quot;bar&quot;, &quot;caz&quot;])]
  
  unique_list = remove_duplicates(duplicate_list)
  
  def remove_duplicates(duplicate_list: List[TestClass]) -&gt; List[TestClass]:
      return list(set(duplicate_list))
  </code></pre>
  <p>Now I want to check the list for duplicates. I tried to convert the list to a set like shown above. I also tried using</p>
  <pre><code>return list( dict.fromkeys(duplicate_list) )
  </code></pre>
  <p>Both approaches do not work as my class contains a list. Because of this the <code>__hash__</code> function generated by the dataclass module does not work. It gives the error: <code>unhashable type: 'list'</code></p>
  <p>What would the correct approach be to remove the duplicate dataclass-elements? Would I need to write a custom <code>__hash__</code> function? Or would it be possible to replace the list with some form of immutable list?</p>