type stringclasses 1
value | task stringlengths 137 560 | plan listlengths 2 4 | code stringlengths 98 383 |
|---|---|---|---|
task_code | Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each entire string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 5. Return the counts as a dictionary. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each category in the input list, strip and uppercase it.",
"If the cleaned string length is >= 5, update its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_5(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
if len(cleaned) >= 5:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rating' and 'label', filters to keep only those with rating <= 23, sorts them by rating in ascending order, and returns a list of the 'label' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records where rating <= 23.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'label' values from the sorted list.",
"Return the list of labels."
] | def select_labels_by_rating_23_ascending(records):
kept = [row for row in records if row["rating"] <= 23]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'cost', keeps only those entries where cost >= 1, then sums the costs grouped by category, and returns a dictionary mapping each category to its total cost. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if cost >= 1, add its cost to the total for its category.",
"Return the totals dictionary."
] | def total_cost_by_category_min_1(records):
totals = {}
for row in records:
if row["cost"] >= 1:
group = row["category"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'cost', computes the average cost per category, then returns a dictionary mapping each category to its average only if that average is >= 11. Do not mutate the input list. | [
"Initialize two dictionaries: one for total cost per category, one for count per category.",
"Loop over each record, updating totals and counts for its category.",
"Compute average for each category as total / count.",
"Return a dictionary of categories whose average >= 11."
] | def qualifying_cost_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / count... |
task_code | Write a Python function that takes two equal-length lists of integers, compares them element-wise using a margin of 75, and returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize counts dictionary with zeros.",
"Zip the two lists together and iterate over each pair.",
"If left - right > 75, increment 'first_ahead'; else if right - left > 75, increment 'second_ahead'; else increment 'within_margin'.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_75(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 75:
counts["first_ahead"] += 1
elif right - left > 75:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 1 within each inner list, multiplies each retained integer by 8, and returns a new nested list preserving the original row structure and order. Do not mutate the input. | [
"Create a new list by iterating over each row of the input.",
"For each row, filter to keep values >= 1.",
"Multiply each kept value by 8.",
"Return the new nested list."
] | def transform_rows_0_8_1(rows):
return [[value * 8 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'values' (a list of integers), and returns a list of 'category' values for which the sum of the integers in 'values' exceeds 59, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute the sum of its 'values' list.",
"If the sum > 59, append the record's 'category' to the result.",
"Return the result list."
] | def categorys_over_total_59(records):
return [row["category"] for row in records if sum(row["values"]) > 59] |
task_code | Write a Python function that takes two dictionaries mapping categories to counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is >= 9. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 9, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_category_counts_min_9(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 9:
result[key] = total
return result |
task_code | Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each entire string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 5. Return the counts as a dictionary. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each topic in the input list, strip and uppercase it.",
"If the cleaned string length is >= 5, update its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_upper_5(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().upper()
if len(cleaned) >= 5:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'score' and 'title', filters to keep only those with score <= 23, sorts them by score in ascending order, and returns a list of the 'title' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records where score <= 23.",
"Sort the filtered list by score in ascending order.",
"Extract the 'title' values from the sorted list.",
"Return the list of titles."
] | def select_titles_by_score_23_ascending(records):
kept = [row for row in records if row["score"] <= 23]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'cost', keeps only those entries where cost >= 1, then sums the costs grouped by topic, and returns a dictionary mapping each topic to its total cost. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if cost >= 1, add its cost to the total for its topic.",
"Return the totals dictionary."
] | def total_cost_by_topic_min_1(records):
totals = {}
for row in records:
if row["cost"] >= 1:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'cost', computes the average cost per topic, then returns a dictionary mapping each topic to its average only if that average is >= 11. Do not mutate the input list. | [
"Initialize two dictionaries: one for total cost per topic, one for count per topic.",
"Loop over each record, updating totals and counts for its topic.",
"Compute average for each topic as total / count.",
"Return a dictionary of topics whose average >= 11."
] | def qualifying_cost_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >... |
task_code | Write a Python function that takes two equal-length lists of integers, compares them element-wise using a margin of 76, and returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize counts dictionary with zeros.",
"Zip the two lists together and iterate over each pair.",
"If left - right > 76, increment 'first_ahead'; else if right - left > 76, increment 'second_ahead'; else increment 'within_margin'.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_76(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 76:
counts["first_ahead"] += 1
elif right - left > 76:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers greater than 1 within each inner list, and returns a new nested list preserving the original row structure and order. Do not mutate the input. | [
"Create a new list by iterating over each row of the input.",
"For each row, filter to keep values > 1.",
"Return the new nested list."
] | def transform_rows_1_8_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'values' (a list of integers), and returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 59, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute the sum of its 'values' list.",
"If the sum > 59, append the record's 'topic' to the result.",
"Return the result list."
] | def topics_over_total_59(records):
return [row["topic"] for row in records if sum(row["values"]) > 59] |
task_code | Write a Python function that takes two dictionaries mapping topics to counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is >= 9. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 9, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_topic_counts_min_9(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 9:
result[key] = total
return result |
task_code | Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each entire string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 5. Return the counts as a dictionary. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each region in the input list, strip and uppercase it.",
"If the cleaned string length is >= 5, update its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_upper_5(regions):
counts = {}
for region in regions:
cleaned = region.strip().upper()
if len(cleaned) >= 5:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'score' and 'name', filters to keep only those with score <= 23, sorts them by score in ascending order, and returns a list of the 'name' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records where score <= 23.",
"Sort the filtered list by score in ascending order.",
"Extract the 'name' values from the sorted list.",
"Return the list of names."
] | def select_names_by_score_23_ascending(records):
kept = [row for row in records if row["score"] <= 23]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'cost', keeps only those entries where cost >= 1, then sums the costs grouped by region, and returns a dictionary mapping each region to its total cost. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if cost >= 1, add its cost to the total for its region.",
"Return the totals dictionary."
] | def total_cost_by_region_min_1(records):
totals = {}
for row in records:
if row["cost"] >= 1:
group = row["region"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'cost', computes the average cost per region, then returns a dictionary mapping each region to its average only if that average is >= 11. Do not mutate the input list. | [
"Initialize two dictionaries: one for total cost per region, one for count per region.",
"Loop over each record, updating totals and counts for its region.",
"Compute average for each region as total / count.",
"Return a dictionary of regions whose average >= 11."
] | def qualifying_cost_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length lists of integers, compares them element-wise using a margin of 77, and returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize counts dictionary with zeros.",
"Zip the two lists together and iterate over each pair.",
"If left - right > 77, increment 'first_ahead'; else if right - left > 77, increment 'second_ahead'; else increment 'within_margin'.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_77(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 77:
counts["first_ahead"] += 1
elif right - left > 77:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 1 within each inner list, adds 8 to each retained integer, and returns a new nested list preserving the original row structure and order. Do not mutate the input. | [
"Create a new list by iterating over each row of the input.",
"For each row, filter to keep values >= 1.",
"Add 8 to each kept value.",
"Return the new nested list."
] | def transform_rows_2_8_1(rows):
return [[value + 8 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'values' (a list of integers), and returns a list of 'region' values for which the sum of the integers in 'values' exceeds 59, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute the sum of its 'values' list.",
"If the sum > 59, append the record's 'region' to the result.",
"Return the result list."
] | def regions_over_total_59(records):
return [row["region"] for row in records if sum(row["values"]) > 59] |
task_code | Write a Python function that takes two dictionaries mapping regions to counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is >= 9. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 9, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_region_counts_min_9(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 9:
result[key] = total
return result |
task_code | Write a Python function that takes a list of team strings, strips leading/trailing whitespace and converts each string to uppercase, then counts how many times each normalized string appears, but only includes those with length at least 5. Return a dictionary mapping each normalized string to its count. Do not mutate t... | [
"Initialize an empty dictionary for counts.",
"Iterate over each team string: strip whitespace and convert to uppercase.",
"If the cleaned string has length >= 5, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_upper_5(teams):
counts = {}
for team in teams:
cleaned = team.strip().upper()
if len(cleaned) >= 5:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'score' and 'identifier', and returns a list of 'identifier' values from records whose 'score' is <= 23, sorted by 'score' in ascending order. Do not mutate the input list. | [
"Filter the list to keep only records with score <= 23.",
"Sort the filtered records by score in ascending order.",
"Extract the 'identifier' values from the sorted records.",
"Return the list of identifiers."
] | def select_identifiers_by_score_23_ascending(records):
kept = [row for row in records if row["score"] <= 23]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'cost', and returns a dictionary mapping each team to the sum of its costs, but only including entries where cost >= 1. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if cost >= 1, add cost to the team's total.",
"Return the totals dictionary."
] | def total_cost_by_team_min_1(records):
totals = {}
for row in records:
if row["cost"] >= 1:
group = row["team"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'cost', and returns a dictionary mapping each team to its average cost, but only including teams whose average cost is at least 11. Do not mutate the input list. | [
"Initialize two dictionaries: one for total cost per team, one for count per team.",
"Iterate over each record: add cost to team's total and increment count.",
"Compute average for each team as total/count.",
"Return a dictionary of teams whose average >= 11."
] | def qualifying_cost_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ... |
task_code | Write a Python function that takes two equal-length lists of integers and returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' counting how many pairs satisfy: first > second + 78, second > first + 78, or neither. Do not mutate the input lists. | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over pairs using zip: compare left and right.",
"If left - right > 78, increment 'first_ahead'; else if right - left > 78, increment 'second_ahead'; else increment 'within_margin'.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_78(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 78:
counts["first_ahead"] += 1
elif right - left > 78:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only the integers >= 1, each multiplied by 9, preserving the order of rows and elements. Do not mutate the input. | [
"Iterate over each inner list (row).",
"For each row, filter values >= 1 and multiply each by 9.",
"Collect the transformed rows into a new list.",
"Return the new nested list."
] | def transform_rows_0_9_1(rows):
return [[value * 9 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (a list of integers), and returns a list of 'team' values whose sum of 'values' exceeds 59, preserving original order. Do not mutate the input list. | [
"Iterate over each record.",
"Compute the sum of the 'values' list.",
"If the sum > 59, append the 'team' to a result list.",
"Return the result list."
] | def teams_over_total_59(records):
return [row["team"] for row in records if sum(row["values"]) > 59] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts and returns a new dictionary containing keys from the union of both dictionaries, where the value is the sum of counts from both (treating missing keys as 0), but only if the total is at least 9. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 9, add key: total to result.",
"Return the result dictionary."
] | def combine_team_counts_min_9(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 9:
result[key] = total
return result |
task_code | Write a Python function that takes a list of group strings, strips whitespace and converts to uppercase, then counts occurrences of each normalized string with length >= 5. Return a dictionary of counts. Do not mutate the input. | [
"Initialize empty counts dictionary.",
"For each group: strip and convert to uppercase.",
"If length >= 5, increment count.",
"Return counts."
] | def count_clean_groups_upper_5(groups):
counts = {}
for group in groups:
cleaned = group.strip().upper()
if len(cleaned) >= 5:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries with keys 'score' and 'label', returns a list of 'label' values from records with score <= 23, sorted by score ascending. Do not mutate the input. | [
"Filter records with score <= 23.",
"Sort filtered records by score ascending.",
"Extract 'label' values.",
"Return the list."
] | def select_labels_by_score_23_ascending(records):
kept = [row for row in records if row["score"] <= 23]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'group' and 'cost', returns a dictionary mapping each group to the sum of its costs where cost >= 1. Do not mutate the input. | [
"Initialize empty totals dictionary.",
"Iterate: if cost >= 1, add cost to group's total.",
"Return totals."
] | def total_cost_by_group_min_1(records):
totals = {}
for row in records:
if row["cost"] >= 1:
group = row["group"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with keys 'group' and 'cost', returns a dictionary mapping each group to its average cost, but only if the average is >= 11. Do not mutate the input. | [
"Initialize totals and counts dictionaries.",
"For each record: add cost to group total, increment count.",
"Compute average per group.",
"Return dictionary of groups with average >= 11."
] | def qualifying_cost_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >... |
task_code | Write a Python function that takes two equal-length integer lists and returns a dictionary counting pairs where first > second + 79, second > first + 79, or neither. Do not mutate the inputs. | [
"Initialize counts with three keys set to 0.",
"Zip through pairs: compare left and right.",
"Increment appropriate counter.",
"Return counts."
] | def compare_pairs_with_margin_79(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 79:
counts["first_ahead"] += 1
elif right - left > 79:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only integers greater than 1, preserving order. Do not mutate the input. | [
"Iterate over each row.",
"Filter values > 1.",
"Collect filtered rows into a new list.",
"Return the new list."
] | def transform_rows_1_9_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'group' and 'values' (list of ints), returns a list of 'group' values whose sum of 'values' exceeds 59, preserving order. Do not mutate the input. | [
"Iterate over records.",
"Compute sum of 'values'.",
"If sum > 59, append 'group' to result.",
"Return result."
] | def groups_over_total_59(records):
return [row["group"] for row in records if sum(row["values"]) > 59] |
task_code | Write a Python function that takes two dictionaries of group counts and returns a new dictionary with keys from the union, values are sums (missing treated as 0), but only if total >= 9. Do not mutate inputs. | [
"Get union of keys.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 9, add to result.",
"Return result."
] | def combine_group_counts_min_9(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 9:
result[key] = total
return result |
task_code | Write a Python function that takes a list of tag strings, strips whitespace and converts to lowercase, then counts occurrences of each normalized string with length >= 6. Return a dictionary of counts. Do not mutate the input. | [
"Initialize empty counts dictionary.",
"For each tag: strip and convert to lowercase.",
"If length >= 6, increment count.",
"Return counts."
] | def count_clean_tags_lower_6(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries with keys 'priority' and 'title', returns a list of 'title' values from records with priority <= 23, sorted by priority ascending. Do not mutate the input. | [
"Filter records with priority <= 23.",
"Sort filtered records by priority ascending.",
"Extract 'title' values.",
"Return the list."
] | def select_titles_by_priority_23_ascending(records):
kept = [row for row in records if row["priority"] <= 23]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'tag' and 'sales', returns a dictionary mapping each tag to the sum of its sales where sales >= 1. Do not mutate the input. | [
"Initialize empty totals dictionary.",
"Iterate: if sales >= 1, add sales to tag's total.",
"Return totals."
] | def total_sales_by_tag_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with keys 'tag' and 'sales', returns a dictionary mapping each tag to its average sales, but only if the average is >= 11. Do not mutate the input. | [
"Initialize totals and counts dictionaries.",
"For each record: add sales to tag total, increment count.",
"Compute average per tag.",
"Return dictionary of tags with average >= 11."
] | def qualifying_sales_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ... |
task_code | Write a Python function that takes two equal-length integer lists and returns a dictionary counting pairs where first > second + 80, second > first + 80, or neither. Do not mutate the inputs. | [
"Initialize counts with three keys set to 0.",
"Zip through pairs: compare left and right.",
"Increment appropriate counter.",
"Return counts."
] | def compare_pairs_with_margin_80(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 80:
counts["first_ahead"] += 1
elif right - left > 80:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only integers >= 1, each increased by 9, preserving order. Do not mutate the input. | [
"Iterate over each row.",
"For each row, filter values >= 1 and add 9 to each.",
"Collect transformed rows into a new list.",
"Return the new list."
] | def transform_rows_2_9_1(rows):
return [[value + 9 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'tag' and 'values' (list of ints), returns a list of 'tag' values whose sum of 'values' exceeds 60, preserving order. Do not mutate the input. | [
"Iterate over records.",
"Compute sum of 'values'.",
"If sum > 60, append 'tag' to result.",
"Return result."
] | def tags_over_total_60(records):
return [row["tag"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries of tag counts and returns a new dictionary with keys from the union, values are sums (missing treated as 0), but only if total >= 10. Do not mutate inputs. | [
"Get union of keys.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 10, add to result.",
"Return result."
] | def combine_tag_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips whitespace and converts to lowercase, then counts occurrences of each normalized string with length >= 6. Return a dictionary of counts. Do not mutate the input. | [
"Initialize empty counts dictionary.",
"For each label: strip and convert to lowercase.",
"If length >= 6, increment count.",
"Return counts."
] | def count_clean_labels_lower_6(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries with keys 'priority' and 'name', returns a list of 'name' values from records with priority <= 23, sorted by priority ascending. Do not mutate the input. | [
"Filter records with priority <= 23.",
"Sort filtered records by priority ascending.",
"Extract 'name' values.",
"Return the list."
] | def select_names_by_priority_23_ascending(records):
kept = [row for row in records if row["priority"] <= 23]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'label' and 'sales', returns a dictionary mapping each label to the sum of its sales where sales >= 1. Do not mutate the input. | [
"Initialize empty totals dictionary.",
"Iterate: if sales >= 1, add sales to label's total.",
"Return totals."
] | def total_sales_by_label_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["label"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with keys 'label' and 'sales', returns a dictionary mapping each label to its average sales, but only if the average is >= 11. Do not mutate the input. | [
"Initialize totals and counts dictionaries.",
"For each record: add sales to label total, increment count.",
"Compute average per label.",
"Return dictionary of labels with average >= 11."
] | def qualifying_sales_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length integer lists and returns a dictionary counting pairs where first > second + 81, second > first + 81, or neither. Do not mutate the inputs. | [
"Initialize counts with three keys set to 0.",
"Zip through pairs: compare left and right.",
"Increment appropriate counter.",
"Return counts."
] | def compare_pairs_with_margin_81(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 81:
counts["first_ahead"] += 1
elif right - left > 81:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only integers >= 1, each multiplied by 10, preserving order. Do not mutate the input. | [
"Iterate over each row.",
"For each row, filter values >= 1 and multiply each by 10.",
"Collect transformed rows into a new list.",
"Return the new list."
] | def transform_rows_0_10_1(rows):
return [[value * 10 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'label' and 'values' (list of ints), returns a list of 'label' values whose sum of 'values' exceeds 60, preserving order. Do not mutate the input. | [
"Iterate over records.",
"Compute sum of 'values'.",
"If sum > 60, append 'label' to result.",
"Return result."
] | def labels_over_total_60(records):
return [row["label"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries of label counts and returns a new dictionary with keys from the union, values are sums (missing treated as 0), but only if total >= 10. Do not mutate inputs. | [
"Get union of keys.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 10, add to result.",
"Return result."
] | def combine_label_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of status strings, strips whitespace and converts to lowercase, then counts occurrences of each normalized string with length >= 6. Return a dictionary of counts. Do not mutate the input. | [
"Initialize empty counts dictionary.",
"For each status: strip and convert to lowercase.",
"If length >= 6, increment count.",
"Return counts."
] | def count_clean_statuss_lower_6(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries with keys 'priority' and 'identifier', returns a list of 'identifier' values from records with priority <= 23, sorted by priority ascending. Do not mutate the input. | [
"Filter records with priority <= 23.",
"Sort filtered records by priority ascending.",
"Extract 'identifier' values.",
"Return the list."
] | def select_identifiers_by_priority_23_ascending(records):
kept = [row for row in records if row["priority"] <= 23]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'status' and 'sales', returns a dictionary mapping each status to the sum of its sales where sales >= 1. Do not mutate the input. | [
"Initialize empty totals dictionary.",
"Iterate: if sales >= 1, add sales to status's total.",
"Return totals."
] | def total_sales_by_status_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["status"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with keys 'status' and 'sales', returns a dictionary mapping each status to its average sales, but only if the average is >= 11. Do not mutate the input. | [
"Initialize totals and counts dictionaries.",
"For each record: add sales to status total, increment count.",
"Compute average per status.",
"Return dictionary of statuses with average >= 11."
] | def qualifying_sales_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length integer lists and returns a dictionary counting pairs where first > second + 82, second > first + 82, or neither. Do not mutate the inputs. | [
"Initialize counts with three keys set to 0.",
"Zip through pairs: compare left and right.",
"Increment appropriate counter.",
"Return counts."
] | def compare_pairs_with_margin_82(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 82:
counts["first_ahead"] += 1
elif right - left > 82:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only integers greater than 1, preserving order. Do not mutate the input. | [
"Iterate over each row.",
"Filter values > 1.",
"Collect filtered rows into a new list.",
"Return the new list."
] | def transform_rows_1_10_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'status' and 'values' (list of ints), returns a list of 'status' values whose sum of 'values' exceeds 60, preserving order. Do not mutate the input. | [
"Iterate over records.",
"Compute sum of 'values'.",
"If sum > 60, append 'status' to result.",
"Return result."
] | def statuss_over_total_60(records):
return [row["status"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries of status counts and returns a new dictionary with keys from the union, values are sums (missing treated as 0), but only if total >= 10. Do not mutate inputs. | [
"Get union of keys.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 10, add to result.",
"Return result."
] | def combine_status_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of category strings, strips whitespace and converts to lowercase, then counts occurrences of each normalized string with length >= 6. Return a dictionary of counts. Do not mutate the input. | [
"Initialize empty counts dictionary.",
"For each category: strip and convert to lowercase.",
"If length >= 6, increment count.",
"Return counts."
] | def count_clean_categorys_lower_6(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries with keys 'priority' and 'label', returns a list of 'label' values from records with priority <= 23, sorted by priority ascending. Do not mutate the input. | [
"Filter records with priority <= 23.",
"Sort filtered records by priority ascending.",
"Extract 'label' values.",
"Return the list."
] | def select_labels_by_priority_23_ascending(records):
kept = [row for row in records if row["priority"] <= 23]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'category' and 'sales', returns a dictionary mapping each category to the sum of its sales where sales >= 1. Do not mutate the input. | [
"Initialize empty totals dictionary.",
"Iterate: if sales >= 1, add sales to category's total.",
"Return totals."
] | def total_sales_by_category_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["category"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with keys 'category' and 'sales', returns a dictionary mapping each category to its average sales, but only if the average is >= 11. Do not mutate the input. | [
"Initialize totals and counts dictionaries.",
"For each record: add sales to category total, increment count.",
"Compute average per category.",
"Return dictionary of categories with average >= 11."
] | def qualifying_sales_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / cou... |
task_code | Write a Python function that takes two equal-length integer lists and returns a dictionary counting pairs where first > second + 83, second > first + 83, or neither. Do not mutate the inputs. | [
"Initialize counts with three keys set to 0.",
"Zip through pairs: compare left and right.",
"Increment appropriate counter.",
"Return counts."
] | def compare_pairs_with_margin_83(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 83:
counts["first_ahead"] += 1
elif right - left > 83:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only integers >= 1, each increased by 10, preserving order. Do not mutate the input. | [
"Iterate over each row.",
"For each row, filter values >= 1 and add 10 to each.",
"Collect transformed rows into a new list.",
"Return the new list."
] | def transform_rows_2_10_1(rows):
return [[value + 10 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'category' and 'values' (list of ints), returns a list of 'category' values whose sum of 'values' exceeds 60, preserving order. Do not mutate the input. | [
"Iterate over records.",
"Compute sum of 'values'.",
"If sum > 60, append 'category' to result.",
"Return result."
] | def categorys_over_total_60(records):
return [row["category"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries of category counts and returns a new dictionary with keys from the union, values are sums (missing treated as 0), but only if total >= 10. Do not mutate inputs. | [
"Get union of keys.",
"For each key, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 10, add to result.",
"Return result."
] | def combine_category_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of topic strings, strips whitespace and converts each to lowercase, keeps only those with length at least 6, and returns a dictionary counting occurrences of each normalized string. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic: strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 6, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_lower_6(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep those where 'quality' is <= 23, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values in that sorted order. The input list must not be mutated. | [
"Filter the list to keep only records with quality <= 23.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'title' values from the sorted records.",
"Return the list of titles."
] | def select_titles_by_quality_23_ascending(records):
kept = [row for row in records if row["quality"] <= 23]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'sales', keeps only entries where sales is at least 1, and returns a new dictionary mapping each topic to the total sales for that topic. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 1, add sales to the total for its topic.",
"Return the totals dictionary."
] | def total_sales_by_topic_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'sales', computes the average sales per topic, and returns a dictionary mapping each topic to its average only if the average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total sales per topic, one for count per topic.",
"Iterate over each record: add sales to the total and increment count for its topic.",
"Compute average for each topic as total divided by count.",
"Return a dictionary of topics with average >= 11."
] | def qualifying_sales_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 84, and returns a dictionary with counts for 'first_ahead' (first minus second > 84), 'second_ahead' (second minus first > 84), and 'within_margin' (otherwise). The input lists must not be mutated. | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over pairs using zip: compute difference.",
"If first - second > 84, increment first_ahead; else if second - first > 84, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_84(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 84:
counts["first_ahead"] += 1
elif right - left > 84:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 1 within each inner list, multiplies each retained integer by 11, and returns a new nested list preserving the original row order. The input must not be mutated. | [
"Create a new empty list for the result.",
"For each inner list, create a new list with values >= 1 multiplied by 11.",
"Append the transformed inner list to the result.",
"Return the result list."
] | def transform_rows_0_11_1(rows):
return [[value * 11 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and a list of integer 'values', and returns a list of 'topic' values for which the sum of 'values' exceeds 60, preserving original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record: compute sum of its 'values' list.",
"If the sum > 60, append the 'topic' to the result.",
"Return the result list."
] | def topics_over_total_60(records):
return [row["topic"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 10. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 10, add key and total to result.",
"Return the result dictionary."
] | def combine_topic_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of region strings, strips whitespace and converts each to lowercase, keeps only those with length at least 6, and returns a dictionary counting occurrences of each normalized string. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region: strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 6, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_lower_6(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep those where 'quality' is <= 23, sorts the kept records by 'quality' in ascending order, and returns a list of the 'name' values in that sorted order. The input list must not be mutated. | [
"Filter the list to keep only records with quality <= 23.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'name' values from the sorted records.",
"Return the list of names."
] | def select_names_by_quality_23_ascending(records):
kept = [row for row in records if row["quality"] <= 23]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'sales', keeps only entries where sales is at least 1, and returns a new dictionary mapping each region to the total sales for that region. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 1, add sales to the total for its region.",
"Return the totals dictionary."
] | def total_sales_by_region_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["region"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'sales', computes the average sales per region, and returns a dictionary mapping each region to its average only if the average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total sales per region, one for count per region.",
"Iterate over each record: add sales to the total and increment count for its region.",
"Compute average for each region as total divided by count.",
"Return a dictionary of regions with average >= 11."
] | def qualifying_sales_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 85, and returns a dictionary with counts for 'first_ahead' (first minus second > 85), 'second_ahead' (second minus first > 85), and 'within_margin' (otherwise). The input lists must not be mutated. | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over pairs using zip: compute difference.",
"If first - second > 85, increment first_ahead; else if second - first > 85, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_85(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 85:
counts["first_ahead"] += 1
elif right - left > 85:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers greater than 1 within each inner list, and returns a new nested list preserving the original row order. The input must not be mutated. | [
"Create a new empty list for the result.",
"For each inner list, create a new list with values > 1.",
"Append the filtered inner list to the result.",
"Return the result list."
] | def transform_rows_1_11_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and a list of integer 'values', and returns a list of 'region' values for which the sum of 'values' exceeds 60, preserving original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record: compute sum of its 'values' list.",
"If the sum > 60, append the 'region' to the result.",
"Return the result list."
] | def regions_over_total_60(records):
return [row["region"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 10. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 10, add key and total to result.",
"Return the result dictionary."
] | def combine_region_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of team strings, strips whitespace and converts each to lowercase, keeps only those with length at least 6, and returns a dictionary counting occurrences of each normalized string. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each team: strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 6, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_lower_6(teams):
counts = {}
for team in teams:
cleaned = team.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep those where 'quality' is <= 23, sorts the kept records by 'quality' in ascending order, and returns a list of the 'identifier' values in that sorted order. The input list must not be mutated. | [
"Filter the list to keep only records with quality <= 23.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'identifier' values from the sorted records.",
"Return the list of identifiers."
] | def select_identifiers_by_quality_23_ascending(records):
kept = [row for row in records if row["quality"] <= 23]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'sales', keeps only entries where sales is at least 1, and returns a new dictionary mapping each team to the total sales for that team. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 1, add sales to the total for its team.",
"Return the totals dictionary."
] | def total_sales_by_team_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["team"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'sales', computes the average sales per team, and returns a dictionary mapping each team to its average only if the average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total sales per team, one for count per team.",
"Iterate over each record: add sales to the total and increment count for its team.",
"Compute average for each team as total divided by count.",
"Return a dictionary of teams with average >= 11."
] | def qualifying_sales_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >... |
task_code | Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 86, and returns a dictionary with counts for 'first_ahead' (first minus second > 86), 'second_ahead' (second minus first > 86), and 'within_margin' (otherwise). The input lists must not be mutated. | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over pairs using zip: compute difference.",
"If first - second > 86, increment first_ahead; else if second - first > 86, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_86(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 86:
counts["first_ahead"] += 1
elif right - left > 86:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 1 within each inner list, adds 11 to each retained integer, and returns a new nested list preserving the original row order. The input must not be mutated. | [
"Create a new empty list for the result.",
"For each inner list, create a new list with values >= 1 plus 11.",
"Append the transformed inner list to the result.",
"Return the result list."
] | def transform_rows_2_11_1(rows):
return [[value + 11 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and a list of integer 'values', and returns a list of 'team' values for which the sum of 'values' exceeds 60, preserving original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record: compute sum of its 'values' list.",
"If the sum > 60, append the 'team' to the result.",
"Return the result list."
] | def teams_over_total_60(records):
return [row["team"] for row in records if sum(row["values"]) > 60] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 10. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 10, add key and total to result.",
"Return the result dictionary."
] | def combine_team_counts_min_10(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 10:
result[key] = total
return result |
task_code | Write a Python function that takes a list of group strings, strips whitespace and converts each to lowercase, keeps only those with length at least 6, and returns a dictionary counting occurrences of each normalized string. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each group: strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 6, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_lower_6(groups):
counts = {}
for group in groups:
cleaned = group.strip().lower()
if len(cleaned) >= 6:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep those where 'quality' is <= 23, sorts the kept records by 'quality' in ascending order, and returns a list of the 'label' values in that sorted order. The input list must not be mutated. | [
"Filter the list to keep only records with quality <= 23.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'label' values from the sorted records.",
"Return the list of labels."
] | def select_labels_by_quality_23_ascending(records):
kept = [row for row in records if row["quality"] <= 23]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'group' and 'sales', keeps only entries where sales is at least 1, and returns a new dictionary mapping each group to the total sales for that group. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 1, add sales to the total for its group.",
"Return the totals dictionary."
] | def total_sales_by_group_min_1(records):
totals = {}
for row in records:
if row["sales"] >= 1:
group = row["group"]
totals[group] = totals.get(group, 0) + row["sales"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'group' and 'sales', computes the average sales per group, and returns a dictionary mapping each group to its average only if the average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total sales per group, one for count per group.",
"Iterate over each record: add sales to the total and increment count for its group.",
"Compute average for each group as total divided by count.",
"Return a dictionary of groups with average >= 11."
] | def qualifying_sales_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.