On Sat, Feb 5, 2022, 12:19 PM Mirmojtaba Gharibi <[email protected]>
wrote:
>
> With my proposal, using := to init (similar to how in math parlance, the
> := is used for defining something for the first time)
>
> Dic = {} # format fruit:count
> For fruit in fruits:
> Dic[fruit]:= 0
> Dic[fruit]+=1
>
To my eye, this does not look like a conditional assignment. And how would
an operator like this work with objects other than dicts?
Besides, it's easier and clearer to write this as
dic = defaultdict(int)
for fruit in fruits:
dic[fruit] += 1
--- Bruce
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/TTWOSADQXTL6FMRYBSZGCGQWWH2UWX6W/
Code of Conduct: http://python.org/psf/codeofconduct/