Sum of Values by Key

PYTHON coding challenge · Difficulty: easy · Topic: Pandas GroupBy Aggregation · +50 XP

Problem

Given a list of tuples where each tuple contains a key and a value, calculate the sum of values for each unique key. This operation is analogous to a group-by key operation followed by summing in data processing.

Example Input

The data below is already defined — do not redefine it.

`python

data = [('a', 1), ('b', 2), ('a', 3), ('b', 4), ('c', 5)]

`

Expected Output

`

{'a': 4, 'b': 6, 'c': 5}

`

Notes

What this PYTHON challenge teaches you

“Sum of Values by Key” is a easy-level PYTHON challenge focused on Pandas GroupBy Aggregation. Working through it gives you hands-on practice with dictionary, aggregation, group-by — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. 1 ≤ len(data) ≤ 100,000
  2. Each tuple contains a string key and an integer value
  3. Keys are non-empty strings with length ≤ 10
  4. Values are integers in range [-10^9, 10^9]
  5. Return a dictionary with string keys and integer sums as values

How to practise it on PySpark.in

Open the challenge, write your Python code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related PYTHON challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The PYTHON environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated easy and covers Pandas GroupBy Aggregation.

Solve this challenge free on PySpark.in