小编aa *_* aa的帖子

Counting Lists and Adding to a new Dictionary (Python)

I'm working with dictionaries and was wondering how I could output a dictionary where its key is the word that occurs in a given dictionary and its value is the number of times it occurs within that dictionary.

So say for example,

A = {'#1': ['Yellow', 'Blue', 'Red'], '#2': ['White', 'Purple', 'Purple', 'Red']}
B - []
for key in A:
    B.append(A[key])

>>> B
>>> [['Yellow', 'Blue', 'Red'], ['White', 'Purple', 'Purple', 'Red']]
Run Code Online (Sandbox Code Playgroud)

After returning the respective values of the keys, I …

python dictionary dictionary-comprehension

1
推荐指数
1
解决办法
30
查看次数