0
myset=set()

myset.add(2)  #it is accepted

myset.add("name") #it is also accepted

The line below is throwing an error. I just want to know as per definition of sets it is an unordered pair which won't keep duplicate copies. But why can't it store lists?

myset.add([1,2,3]) 
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • Every `list` is mutable, so if something else has a reference to the `list` in a `set`, it could be modified and lead to the potential of two items in the `set` being identical. – quamrana May 29 '20 at 11:39
  • Thanks for the comment I think this is the same reason why sets won't take dictionaries also. Am I right?? so sets only take Integers floating-point numbers and strings . Am i right?? – Suneeldatta Kolipakula May 29 '20 at 11:44
  • Yes, a `dict` cannot be added to a `set`. As for other things, take a look at some of the answers in the linked question. – quamrana May 29 '20 at 13:07

0 Answers0