-2

Input:

["Red", "Blue", "Yellow", "Red", "Blue", "Green", "Red"]

Output

["Red":3, "Blue":2, "Yellow":1, "Green":1

The value is the amount of times the color popped up.

Dave Costa
  • 47,262
  • 8
  • 56
  • 72

1 Answers1

1
my_list = ["Red", "Blue", "Yellow", "Red", "Blue", "Green", "Red"]
my_dict = {}
for i in my_list:
    if i in my_dict:
        my_dict[i] += 1
    else:
        my_dict[i] = 1
izhang05
  • 744
  • 2
  • 11
  • 26