Extension of python/json syntax to support explicitly sets and ordered dict.

Hi all,
few days ago I thought about a way to rapresent sets and ordered dicts using a json compatible syntax, these are my conclusions:
A set could be defined as { item1, item2, item3[...] } with {,} as an empty set
An ordered dict could be defined as [ item1: value1, item2: value2 ... ] with [:] ase an empty odered dict
It could be used inside python code or to serialize python structures in a json-like format (pyson maybe ?).
What do you think about ?
Kind regards, Matteo.

On Thu, Sep 07, 2017 at 01:36:31PM +0200, Matteo Nastasi wrote:
A set could be defined as { item1, item2, item3[...] }
Guido's time machine strikes again. Python 3:
py> s = {1, 2, 3} py> type(s) <class 'set'>
with {,} as an empty set
That looks like a typo. I don't think that having a literal for empty sets is important enough that we need worry about the lack.
An ordered dict could be defined as [ item1: value1, item2: value2 ... ] with [:] ase an empty odered dict
I think that's been proposed before.
I don't hate that suggestion, but I don't think its very useful either. We already have a de facto "Ordered Mapping" literal that can be passed to the OrderedDict constructor:
OrderedDict( [(key1, value1), (key2, value2), (key3, value3), ...] )
Its not quite as compact, but it isn't too awful. And if you really don't like it, try:
OrderedDict(zip(keys, values))

I was thinking about an extended json too, not just python syntax.
What do you think about it ?
Regards and thank you for your time.
Matteo.
On Thu, Sep 07, 2017 at 09:54:15PM +1000, Steven D'Aprano wrote:
On Thu, Sep 07, 2017 at 01:36:31PM +0200, Matteo Nastasi wrote:
A set could be defined as { item1, item2, item3[...] }
Guido's time machine strikes again. Python 3:
py> s = {1, 2, 3} py> type(s) <class 'set'>
with {,} as an empty set
That looks like a typo. I don't think that having a literal for empty sets is important enough that we need worry about the lack.
An ordered dict could be defined as [ item1: value1, item2: value2 ... ] with [:] ase an empty odered dict
I think that's been proposed before.
I don't hate that suggestion, but I don't think its very useful either. We already have a de facto "Ordered Mapping" literal that can be passed to the OrderedDict constructor:
OrderedDict( [(key1, value1), (key2, value2), (key3, value3), ...] )
Its not quite as compact, but it isn't too awful. And if you really don't like it, try:
OrderedDict(zip(keys, values))
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

On Thu, Sep 7, 2017 at 9:59 PM, Matteo Nastasi nastasi@alternativeoutput.it wrote:
I was thinking about an extended json too, not just python syntax.
What do you think about it ?
Regards and thank you for your time.
Extend JSON? No thank you. Down the path of extending simple standards in proprietary ways lies a madness that I do not wish on my best friends, much less my worst enemies.
ChrisA
participants (3)
-
Chris Angelico
-
Matteo Nastasi
-
Steven D'Aprano