[Python-Dev] Unordered tuples/lists (original) (raw)

Ben Finney ben+python at benfinney.id.au
Wed May 19 02:19:07 CEST 2010


Gustavo Narea <me at gustavonarea.net> writes:

I've been searching for a data structure like a tuple/list but unordered -- like a set, but duplicated elements shouldn't be removed.

By that description, you're looking for the “Bag” pattern.

[…]

A multiset is not exactly what I need: I still need to use the elements in the order they were given.

This appears to contradict your explicit request that the collection type be unordered.

[…]

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).

Okay, so you want something rather special; it would be misleading to call this an unordered type, since you do want ordering preserved. It's only the comparison operators that would ignore ordering.

AFAIK you'll need to design and implement this yourself.

I will write a PEP to elaborate on this if you think it'd be nice to have. Or, should I have written the PEP first?

Either way; but I think this discussion belongs on ‘python-ideas’ while the behaviour is still being designed.

-- \ “On the internet you simply can't outsource parenting.” —Eliza | `\ Cussen, Top 10 Internet Filter Lies, The Punch, 2010-03-25 | o_) | Ben Finney



More information about the Python-Dev mailing list