Counting Even Numbers in a List

  • Share this:

Code introduction


This function calculates the count of all even numbers in a given list and returns a dictionary where the keys are the even numbers and the values are the counts of their occurrences in the list.


Technology Stack : collections

Code Type : Function

Code Difficulty : Intermediate


                
                    
def a_sum_pairs(numbers):
    pairs = {}
    for num in numbers:
        if num % 2 == 0:
            pairs[num] = pairs.get(num, 0) + 1
    return pairs                
              
Tags: