0

I have the following code:

 d1=set()
 d2=set()
 d1={[12,1]}  
print(d1 & d2)

error:

TypeError: unhashable type: 'list'

What does this mean? Cant the set contain a list element? How do we rectify?

Thanks, Sonia

  • 1
    @DhavalTaunk, no, you're not right. – Olvin Roght Apr 05 '20 at 06:04
  • @DhavalTaunk, `{ }` declarres set as well as dict, you wrote opposit. – Olvin Roght Apr 05 '20 at 06:07
  • @DhavalTaunk: Braces are used for set literals too. [Have an example.](https://ideone.com/KDkT3I) The existing use for dict literals means you can't use braces for an empty set, but other than that, there's no conflict. – user2357112 Apr 05 '20 at 06:07
  • `set([12, 1])` would create a set whose elements are `12` and `1`, not a set with a list as an element. A list cannot be an element of a set. – user2357112 Apr 05 '20 at 06:09

0 Answers0