after sorted from the lists

Ben Bush pythonnew at gmail.com
Tue Nov 22 12:31:28 EST 2005


On 11/22/05, Ben Bush <pythonnew at gmail.com> wrote:
> On 11/22/05, jepler at unpythonic.net <jepler at unpythonic.net> wrote:
> > >>> ll = [[1,2],[2,1],[3,1],[1,4],[3,3],[1,4]]
> > >>> ls = [frozenset(i) for i in ll]
> > >>> ss = set(ls)
> > >>> ss
> > set([frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4]), frozenset([3])])
> > >>> [list(i) for i in ss]
> > [[1, 3], [1, 2], [1, 4], [3]]
> why this happens?
> >>> from sets import *
> >>> ll = [[1,2],[2,1],[3,1],[1,4],[3,3],[1,4]]
> >>> ls = [frozenset(i) for i in ll]
> Traceback (most recent call last):
>  File "<interactive input>", line 1, in ?
> NameError: name 'frozenset' is not defined
>
I know that:
Python 2.3 introduced the sets module. C implementations of set data
types have now been added to the Python core as two new built-in
types, set(iterable) and frozenset(iterable).
But why it does not work in my machine?
PythonWin 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit
(Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au)
- see 'Help/About PythonWin' for further copyright information.
>>> from sets import *
>>> dir(frozenset)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'frozenset' is not defined



More information about the Python-list mailing list