On Fri, Mar 7, 2008 at 10:57 AM, William Stein <[EMAIL PROTECTED]> wrote: > > On Fri, Mar 7, 2008 at 7:35 AM, David Joyner <[EMAIL PROTECTED]> wrote: > > > > Hi: > > Is there a reason why Set only applies to hashable elements? > > Set is implemented using the Python language's builtin set type, which > in turn requires that elements by hashable.
Since SAGE's uniq also required the elements to be hashable, I wonder if anyone things that the above routine should replace it? > > > > It is faster than > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560 > > at removing duplicates from a list (which is what I need) but does not > > apply, for example, to lists of matrices: > > FYI -- If you make the matrices immutable then you can hash them. Thanks. > > > > > > > > sage: MS = MatrixSpace(GF(7),2,2) > > sage: A = MS.identity_matrix() > > sage: B = 2*A > > sage: L = [A,A,B] > > sage: Set(L) > > > --------------------------------------------------------------------------- > > <type 'exceptions.TypeError'> Traceback (most recent call > last) > > > > /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/<ipython console> in <module>() > > > > > /home/wdj/wdj/sagefiles/sage-2.10.3.rc2/local/lib/python2.5/site-packages/sage/sets/set.py > > in Set(X) > > 78 raise TypeError, "Element has no defined underlying set" > > 79 elif isinstance(X, (list, tuple, set, frozenset)): > > ---> 80 return Set_object_enumerated(frozenset(X)) > > 81 try: > > 82 if X.is_finite(): > > > > /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_modn_dense.pyx in > > sage.matrix.matrix_modn_dense.Matrix_modn_dense.__hash__() > > > > /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_dense.pyx in > > sage.matrix.matrix_dense.Matrix_dense._hash() > > > > <type 'exceptions.TypeError'>: mutable matrices are unhashable > > > > > > - David Joyner > > > > > > > > > > > -- > William Stein > Associate Professor of Mathematics > University of Washington > http://wstein.org > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---