Q:

Can list become an element of set in python

I really wonder why the second one gives an error:
It would be really great if some one could pls highlight can we use lists as an element in set or it's not allowed to have any mutable object inside a set.
1)
>>> x = set(["Perl", "Python", "Java"])
>>> x
set(['Python', 'Java', 'Perl'])
>>> 

2)  
>>> cities = set((["Python","Perl"], ["Paris", "Berlin", "London"]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> 

A:

As you noted, you can't have a list as a member of a set (because it's not hashable).
I think you've been confused by the repr of the set in your first example. The output set(['Python', 'Java', 'Perl']) doesn't indicate that the set contains a 3-element list. Rather, it contains the three strings, with the list just being part of the notation the repr uses (since the set constructor expects an iterable of items). Note that the order of the items changes from your input to the the arbitrary order of the output!
In Python 3, the set type's repr uses set-literal syntax instead:
>>> x = set(["Perl", "Python", "Java"])
>>> x
{'Java', 'Perl', 'Python'}

