
Feb. 5, 2022
8:18 p.m.
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