[Python-Dev] Unordered tuples/lists
Oleg Broytman
phd at phd.pp.ru
Wed May 19 01:53:33 CEST 2010
On Tue, May 18, 2010 at 11:13:42PM +0100, Gustavo Narea wrote:
> To sum up, it would behave like a tuple or a list, except when it's compared
> with another object: They would be equivalent if they're both unordered
> tuples/lists, and have the same elements. There can be mutable and immutable
> editions (UnorderedList and UnorderedTuple, respectively).
class UnorderedList(list):
def __eq__(self, other):
if not isinstance(other, UnorderedList):
return False
return sorted(self) == sorted(other)
def __ne__(self, other):
return not self.__eq__(other)
Do you need more than that?
Oleg.
--
Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-Dev
mailing list