d = {:name, :addr, ’tel': '123-4567’}
Stephen J. Turnbulld = {first : first, last, addr1, addr2}I'm not a huge fan of this solution. It feels a bit like a hack instead of an intended syntax. Since prefixing characters on strings is already a thing, I lean more towards that solution. It's slightly easier to search (e.g. if the notation was d{literal1, literal2, etc}, one might search for "python d-dict"). However, If the above notation gains favor, perhaps it would be better to allow an empty ':' followed by a comma:
d = {:, first, last, addr1, addr2}
I don't much like the Perlyness of that syntax, but it's similar to using a prefix and it might lead to more explicit empty literals like {:} and {,} for dict and set respectively. I'm pretty sure that notation for empty literals has been discussed and rejected before, so I apologize if this brings up well-trodden ground. I'm pretty neutral on the proposal in general.
It may also be possible to add a constructor to dict like:
d = dict.from_locals('first', 'last', 'addr1', 'addr2')
d['tel'] = '123-456-789'
It might require a bit of stack inspection or some other magic, but it should be possible. It might be difficult for IDEs to recognize and hint and it might also be a blind-spot for re-factoring (if you change the name of a local variable)._______________________________________________On Wed, Jun 10, 2020 at 3:06 AM Stephen J. Turnbull <turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:Chris Angelico writes:
> On Wed, Jun 10, 2020 at 1:15 PM Stephen J. Turnbull
> <turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
> >
> > Executive summary:
> >
> > Dicts are unordered, so we can distinguish dict from set by the first
> > item (no new notation), and after that default identifiers to (name :
> > in-scope value) items.
>
> Be careful with this assumption. Python's dictionaries DO retain
> order,
Thank you for the reminder! I did forget that point.
> even if you can't easily talk about "the fifth element" [1], so
> anything that imposes requirements on the entry listed
> syntactically first may have consequences.
No requirements imposed! If iteration order matters and you want to
take advantage of abbreviation, you might have to write
d = {first : first, last, addr1, addr2, tel='123-456-789'}
but frequently it would just work naturally:
d = {first : first, last, addr1, addr2}
Admittedly this distinction may be even more subtle than grit on Tim's
screen, or randomizing the hash seed per process. And I suspect that
people who want this feature will prefer the d{} notation for
consistency inside the braces.
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ENXYVRXOAEOBWHN6SQK5K4IJUTRHHXLB/
Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/F2DDRMDOQOMCWATOV2CN3AZTYT3FPVTA/
Code of Conduct: http://python.org/psf/codeofconduct/