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. -- email: nastasi@alternativeoutput.it, matteo.nastasi@gmail.com web: www.alternativeoutput.it irc: #linux-mi@irc.freenode.net linkedin: http://lnkd.in/SPQG87

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

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:
-- email: nastasi@alternativeoutput.it, matteo.nastasi@gmail.com web: www.alternativeoutput.it irc: #linux-mi@irc.freenode.net linkedin: http://lnkd.in/SPQG87

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

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:
-- email: nastasi@alternativeoutput.it, matteo.nastasi@gmail.com web: www.alternativeoutput.it irc: #linux-mi@irc.freenode.net linkedin: http://lnkd.in/SPQG87
participants (3)
-
Chris Angelico
-
Matteo Nastasi
-
Steven D'Aprano