library(tidyverse)
library(readxl)
input = read_excel("files/CH-011.xlsx", range = "B2:E16")
test = read_excel("files/CH-011.xlsx", range = "K2:K6")
result = input %>%
pivot_longer(cols = everything(), names_to = "columns", values_to = "codes") %>%
group_by(codes) %>%
summarise(is_in_col = n_distinct(columns)) %>%
filter(is_in_col >= 3) %>%
select(-is_in_col)
identical(result$codes, test$`Item Code`)
# [1] TRUEOmid - Challenge 11
data-challenges
advanced-exercises
🔰 List 1 List 2 List 3 List 4 Extract all item codes that are repeated at least in 3 out of 4 lists presented in the question table.

Challenge Description
🔰 List 1 List 2 List 3 List 4 Extract all item codes that are repeated at least in 3 out of 4 lists presented in the question table.
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Reshapes the data into the grain required by the task
Aggregates or ranks values at the relevant grouping level
Strengths:
- The R solution stays close to the workbook rule and keeps the transformation compact.
Areas for Improvement:
- The code assumes the sheet structure and source ranges remain stable.
Gem:
- The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd
input_data = pd.read_excel("CH-011.xlsx", usecols="B:E", skiprows=1, nrows=15)
test = pd.read_excel("CH-011.xlsx", usecols="K", skiprows=1, nrows=5)
result = (
input_data.melt(var_name="columns", value_name="codes")
.groupby("codes", as_index=False)["columns"]
.nunique()
.rename(columns={"columns": "is_in_col"})
)
result = result.loc[result["is_in_col"] >= 3, ["codes"]]
print(result["codes"].equals(test["Item Code"]))Logic:
Reads the workbook ranges needed for the challenge
Reshapes the data into the grain required by the task
Aggregates or ranks values at the relevant grouping level
Strengths:
- The Python version follows the same rule in a direct dataframe-oriented implementation.
Areas for Improvement:
- The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
Gem:
- The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.
Difficulty Level
This task is moderate:
The core logic is clear, but the correct transformation pattern is not obvious from the raw input.
The challenge combines multiple reshaping, grouping, or parsing steps.