Python Forum

Full Version: Sets and Lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Can someone please explain to me why when I enter this in python it does not give an error:

print(set([1,2,3]))

but as soon as I enter this it gives an error saying 'unhashable type'.

print(set(([1,2,3],[4,5,6])))

I understand lists are unhashable and arguments for sets can only be of hashable types.
But in here print(set([1,2,3])) the argument the set is taking is also a list (i.e [1,2,3]) no? so it should also give an error too, right?
print(set(([1,2,3],[4,5,6])))
would have to be:
print(set([1,2,3]), set([4,5,6]))
retult:
Output:
{1, 2, 3} {4, 5, 6}
sets cannot be list of lists
thanks, makes sense.