-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
  • 46,065
  • 8
  • 54
  • 71

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
  • 736
  • 1
  • 10
  • 24