Hello there,

I have an idea for initializing a variable the first time it’s created; it
can especially be helpful with containers, and dicts specifically. Let me
demonstrate with some examples:

Dic = {} # format fruit:count
for fruit in fruits:
   If fruit in Dic:
      Dic[fruit]+=1
   Else:
      Dic[fruit]=1

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

Would be great to hear your feedback. Thanks.

Moj
_______________________________________________
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/G4KJNQZYROB3NDWWLWSR5OHD7ZDCQQT4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to