Different types of dicts with letter before the curly braces.

Aaron Brady castironpi at gmail.com
Sun Jun 14 09:27:32 EDT 2009

On Jun 14, 4:02 am, kindly <kin... at gmail.com> wrote:
> I am sure people have thought of this before, but I cant find where.
> I think that python should adapt a way of defining different types of
> mapping functions by proceeding a letter before the curly brackets.
> i.e   ordered = o{},  multidict = m{}  (like paste multidict).  So you
> could define an ordered dict by newordered = o{"llvm" : "ptyhon",
> "parrot" : "perl"} .  (they should also probably have there own
> comprehensions as well o{foo for bar in foobar}).

That kind of stuff is highly explosive, unfortunately.  o{ }, m{ }, d
[ ], and q[ ] are just a few.  But 'collections' is kind of sparse.  I
expect you would also want users to be able to define their own
prefixes, no?  As is, the syntax is not atrocious:

oA= OrderedDict( [ ( pair1 ), ( pair2 ) ]
oA= o{ pair1, pair2 }

At least you can still include literals, and are not restricted to per-
line additions as in C.

> Most packages that I have seen re-
> implement these different container types at one point anyway. It
> seems a shame they are not brought up to the top level, with
> potentially new, cleverer ones that have not been thought of yet.

Do you merely want to populate the 'collections' module, or are the
prefixes essential to your idea?

More information about the Python-list mailing list