![](https://cache.ptt.cc/c/https/i.imgur.com/KrQzV0Ml.jpg?e=1718963823&s=Z_OS5WnlIRCTZ-9KmvF4fQ)
→ stucode: dict_counter = {} 是建立空字典不是空集合。 07/22 18:07
→ stucode: dict_counter[food] 是查詢字典中 key 為 food 變數內容 07/22 18:08
→ stucode: 的對應值為何,假設 07/22 18:08
→ stucode: dict_counter = {'spam': 3, 'egg': 1} 07/22 18:08
→ stucode: food = 'spam' 07/22 18:08
→ stucode: 那 dict_counter[food] 就是 3 07/22 18:08
→ stucode: 而 dict_counter[food] += 1 是把該對應值 +1, 07/22 18:08
→ stucode: 變成 {'spam': 4, 'egg': 1} 07/22 18:09
推 TitanEric: 利用dict作counting 07/22 18:54
→ TitanEric: 個人覺得not in dict比較直覺 也容易閱讀 07/22 18:54
→ yummy8765: =0是指定 +=1是運算 我會這樣理解 07/22 22:42