On Fri, Apr 9, 2021 at 1:30 PM David Mertz <me...@gnosis.cx> wrote:

> I don't do twitter, so hadn't seen Raymond's comment.  But I agree that
> `{*()}` is too-clever-by-half.  Moreover, it's the same character count as
> `set()`, so it doesn't even save anything.
>
> Using five characters to create an empty `set()` really isn't that many. I
> do that all the time.  Proposals to get that down to three characters don't
> feel like any big win.  Actually, I've largely gotten in the habit of
> writing `list()` and `dict()` as well when I want to start with empty
> ones.  I suppose the fact I do that is influenced by having to do it with
> `set()`; but even beyond that, I find it jumps out in intent more than the
> display forms.
>
> The pattern of "Create an empty collection, then add stuff in a loop" is
> quite common, and emphasizing which type of collection is being used is
> useful.  Moreover, the type might be `Queue()`, or `deque()` or `Counter()`
> as well, and I don't expect or want literals for every possible collection.
>

Devil's advocate: it might be nice to not have to import all of those
highly useful collection classes from collections all the time.

What about creating syntax that looks something like:

Counter() < ---- > c{}
Queue() < ---- > q{}
deque() < ---- > dq{}
ChainMap() < ---- > cm{}
OrderedDict() < ---- > od{}
defaultdict(list) < ---- > dd{list}  # this one is admittedly a little weird

And similarly, while you're at it you could do something like:

set() < ---- > s{}

To be clear: I am not proposing a new "alt call" syntax... these are to be
new LITERALS. I see this as sort of analogous to f-string syntax:

f""

One benefit is this could greatly shorten the reprs for ALL of these types.
Consider:

defaultdict(<class 'list'>, {})

rather than:

dd{list}

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/VKUD4M7S3AEU4TRVPW7FMZXVRXNLY7P7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to