Building a dictionary of counts of items in a list

后端 未结 5 1386
广开言路
广开言路 2021-01-02 06:08

I have a List containing a bunch of strings that can occur more than once. I would like to take this list and build a dictionary of the list items as the key and the count

5条回答
  •  天命终不由人
    2021-01-02 06:43

    One idea would be to give the dictionary a default value of zero, so you wouldn't have to special case the first occurrence.

提交回复
热议问题