typeerrorunhashable type'dicts add(( ) { ( ) {( )( ){ ( )( )( in true ( in false no list or dictbut tuple ok unionsame as unionmembershipby complete values tuples in setfor instancemight be used to represent datesrecordsip addressesand so on (more on tuples later in this part of the booksets may also contain modulestype objectsand more sets themselves are mutable tooand so cannot be nested in other sets directlyif you need to store set inside another setthe frozenset built-in call works just like set but creates an immutable set that cannot change and thus can be embedded in other sets set comprehensions in python and in addition to literalspython grew set comprehension construct that was backported for use to python too like the set literal accepts its syntaxbut displays its results in set notation the set comprehension expression is similar in form to the list comprehension we previewed in but is coded in curly braces instead of square brackets and run to make set instead of list set comprehensions run loop and collect the result of an expression on each iterationa loop variable gives access to the current iteration value for use in the collection expression the result is new set you create by running the codewith all the normal set behavior here is set comprehension in (againresult display and order differs in ){ * for in [ ]{ / set comprehension in this expressionthe loop is coded on the rightand the collection expression is coded on the left ( * as for list comprehensionswe get back pretty much what this expression says"give me new set containing squaredfor every in list comprehensions can also iterate across other kinds of objectssuch as strings (the first of the following examples illustrates the comprehension-based way to make set from an existing iterable){ for in 'spam'{' '' '' '' 'same asset('spam'{ for in 'spam'{'pppp''aaaa''ssss''mmmm'{ for in 'spamham'{'pppp''aaaa''hhhh''ssss''mmmm'set of collected expression results { for in 'spam' numeric types