type stringclasses 1
value | task stringlengths 137 560 | plan listlengths 2 4 | code stringlengths 98 383 |
|---|---|---|---|
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 11, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 11), 'second_ahead' (second minus first > 11), and 'within_margin' (otherwise). The input lists must not be... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; for each pair, determine which category applies and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_11_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 11:
counts["first_ahead"] += 1
elif right - left > 11:
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 and structure. The input must not be mutated. | [
"For each inner list, filter to keep values > 1.",
"Collect the filtered inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_1_20_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 a 'tag' key and a 'values' key that is a list of integers, returns a list of 'tag' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the record's 'tag' to the result list.",
"Return the result list."
] | def tags_over_total_64(records):
return [row["tag"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries of tag counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 14, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated. | [
"Initialize an empty result dictionary.",
"Compute the union of keys from both dictionaries.",
"For each key, sum the values (using .get with default 0).",
"If the total >= 14, add the key and total to the result dictionary; return it."
] | def combine_tag_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips leading/trailing whitespace and converts each complete string to lowercase, then counts how many times each normalized string appears among those with length at least 8, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label string, strip and convert to lowercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_lower_8(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' value is less than or equal to 24, sorts the kept records by 'rank' in ascending order, and returns a list of the 'name' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records with rank <= 24.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'name' values from the sorted records into a new list.",
"Return the list of names."
] | def select_names_by_rank_24_ascending(records):
kept = [row for row in records if row["rank"] <= 24]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'label' and 'points', keeps only entries where 'points' is at least 2, sums the retained 'points' grouped by 'label', and returns a dictionary mapping each label to its total. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add its points to the total for its label.",
"Return the totals dictionary."
] | def total_points_by_label_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["label"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'label' and 'points', computes the average points per label, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying label to its average. The input list must not be mutated. | [
"Initialize two dictionaries: one for total points per label, one for count per label.",
"Iterate over each record, updating totals and counts for its label.",
"Compute the average for each label as total divided by count.",
"Return a dictionary of labels whose average is >= 12."
] | def qualifying_points_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["points"]
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, compares each pair of values using a margin of 12, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 12), 'second_ahead' (second minus first > 12), and 'within_margin' (otherwise). The input lists must not be... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; for each pair, determine which category applies and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_12_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 12:
counts["first_ahead"] += 1
elif right - left > 12:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers that are at least 1 within each inner list, adds 20 to each retained integer, and returns a new nested list preserving the original row order and structure. The input must not be mutated. | [
"For each inner list, filter to keep values >= 1.",
"Add 20 to each kept value.",
"Collect the transformed inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_2_20_1(rows):
return [[value + 20 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 a 'label' key and a 'values' key that is a list of integers, returns a list of 'label' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the record's 'label' to the result list.",
"Return the result list."
] | def labels_over_total_64(records):
return [row["label"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries of label counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 14, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated. | [
"Initialize an empty result dictionary.",
"Compute the union of keys from both dictionaries.",
"For each key, sum the values (using .get with default 0).",
"If the total >= 14, add the key and total to the result dictionary; return it."
] | def combine_label_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
result[key] = total
return result |
task_code | Write a Python function that takes a list of status strings, strips leading/trailing whitespace and converts each to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each status in the input list, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_statuss_lower_8(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' key is <= 24, sorts the kept records by 'rank' in ascending order, and returns a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 24.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'identifier' value from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_rank_24_ascending(records):
kept = [row for row in records if row["rank"] <= 24]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'status' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct status, and returns a dictionary mapping status to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its status.",
"Return the totals dictionary."
] | def total_points_by_status_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["status"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'status' and 'points' keys, computes the average points per status, keeps only those averages that are at least 12, and returns a dictionary mapping status to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per status, one for count per status.",
"Iterate over each record, updating totals and counts for its status.",
"Compute the average for each status by dividing total by count.",
"Return a dictionary of status to average only for averages >= 12."
] | def qualifying_points_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["points"]
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 integer lists, compares each pair of values (first list element vs second list element) using a margin of 13, and returns a dictionary with counts for 'first_ahead' (first > second by more than 13), 'second_ahead' (second > first by more than 13), and 'within_margin' ... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 13, then increment 'first_ahead'; else if right - left > 13, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_13_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 13:
counts["first_ahead"] += 1
elif right - left > 13:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2 and multiplies each kept integer by 2, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes value * 2 for each value >= 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_0_2_2(rows):
return [[value * 2 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'status' key and a 'values' key (a list of integers), returns a list of 'status' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'status' to the result list.",
"Return the result list."
] | def statuss_over_total_64(records):
return [row["status"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_status_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
result[key] = total
return result |
task_code | Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each category, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_categorys_lower_8(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' key is <= 24, sorts the kept records by 'rank' in ascending order, and returns a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 24.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'label' value from each sorted record into a new list.",
"Return the list of labels."
] | def select_labels_by_rank_24_ascending(records):
kept = [row for row in records if row["rank"] <= 24]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'category' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct category, and returns a dictionary mapping category to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its category.",
"Return the totals dictionary."
] | def total_points_by_category_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["category"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'category' and 'points' keys, computes the average points per category, keeps only those averages that are at least 12, and returns a dictionary mapping category to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per category, one for count per category.",
"Iterate over each record, updating totals and counts for its category.",
"Compute the average for each category by dividing total by count.",
"Return a dictionary of category to average only for averages >= 12."
] | def qualifying_points_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["points"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / c... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 14, and returns a dictionary with counts for 'first_ahead' (first > second by more than 14), 'second_ahead' (second > first by more than 14), and 'within_margin' (otherwise). Do not mutate the input lists. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 14, then increment 'first_ahead'; else if right - left > 14, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_14_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 14:
counts["first_ahead"] += 1
elif right - left > 14:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers greater than 2, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes each value > 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_1_2_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'category' key and a 'values' key (a list of integers), returns a list of 'category' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'category' to the result list.",
"Return the result list."
] | def categorys_over_total_64(records):
return [row["category"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_category_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
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 to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_topics_lower_8(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'weight' key is <= 24, sorts the kept records by 'weight' in ascending order, and returns a list of the 'title' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 24.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'title' value from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_weight_24_ascending(records):
kept = [row for row in records if row["weight"] <= 24]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'topic' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct topic, and returns a dictionary mapping topic to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its topic.",
"Return the totals dictionary."
] | def total_points_by_topic_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'topic' and 'points' keys, computes the average points per topic, keeps only those averages that are at least 12, and returns a dictionary mapping topic to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per topic, one for count per topic.",
"Iterate over each record, updating totals and counts for its topic.",
"Compute the average for each topic by dividing total by count.",
"Return a dictionary of topic to average only for averages >= 12."
] | def qualifying_points_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["points"]
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, compares each pair of values using a margin of 15, and returns a dictionary with counts for 'first_ahead' (first > second by more than 15), 'second_ahead' (second > first by more than 15), and 'within_margin' (otherwise). Do not mutate the input lists. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 15, then increment 'first_ahead'; else if right - left > 15, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_15_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 15:
counts["first_ahead"] += 1
elif right - left > 15:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2 and adds 2 to each kept integer, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes value + 2 for each value >= 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_2_2_2(rows):
return [[value + 2 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'topic' key and a 'values' key (a list of integers), returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'topic' to the result list.",
"Return the result list."
] | def topics_over_total_64(records):
return [row["topic"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_topic_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
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 to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_regions_lower_8(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'weight' key is <= 24, sorts the kept records by 'weight' in ascending order, and returns a list of the 'name' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 24.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'name' value from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_weight_24_ascending(records):
kept = [row for row in records if row["weight"] <= 24]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'region' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct region, and returns a dictionary mapping region to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its region.",
"Return the totals dictionary."
] | def total_points_by_region_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["region"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'region' and 'points' keys, computes the average points per region, keeps only those averages that are at least 12, and returns a dictionary mapping region to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per region, one for count per region.",
"Iterate over each record, updating totals and counts for its region.",
"Compute the average for each region by dividing total by count.",
"Return a dictionary of region to average only for averages >= 12."
] | def qualifying_points_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["points"]
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 integer lists, compares each pair of values using a margin of 16, and returns a dictionary with counts for 'first_ahead' (first > second by more than 16), 'second_ahead' (second > first by more than 16), and 'within_margin' (otherwise). Do not mutate the input lists. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 16, then increment 'first_ahead'; else if right - left > 16, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_16_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 16:
counts["first_ahead"] += 1
elif right - left > 16:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2 and multiplies each kept integer by 3, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes value * 3 for each value >= 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_0_3_2(rows):
return [[value * 3 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'region' key and a 'values' key (a list of integers), returns a list of 'region' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'region' to the result list.",
"Return the result list."
] | def regions_over_total_64(records):
return [row["region"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_region_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
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 to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each team, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_teams_lower_8(teams):
counts = {}
for team in teams:
cleaned = team.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'weight' key is <= 24, sorts the kept records by 'weight' in ascending order, and returns a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 24.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'identifier' value from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_weight_24_ascending(records):
kept = [row for row in records if row["weight"] <= 24]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'team' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct team, and returns a dictionary mapping team to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its team.",
"Return the totals dictionary."
] | def total_points_by_team_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["team"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'team' and 'points' keys, computes the average points per team, keeps only those averages that are at least 12, and returns a dictionary mapping team to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per team, one for count per team.",
"Iterate over each record, updating totals and counts for its team.",
"Compute the average for each team by dividing total by count.",
"Return a dictionary of team to average only for averages >= 12."
] | def qualifying_points_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["points"]
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, compares each pair of values using a margin of 17, and returns a dictionary with counts for 'first_ahead' (first > second by more than 17), 'second_ahead' (second > first by more than 17), and 'within_margin' (otherwise). Do not mutate the input lists. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 17, then increment 'first_ahead'; else if right - left > 17, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_17_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 17:
counts["first_ahead"] += 1
elif right - left > 17:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers greater than 2, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes each value > 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_1_3_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'team' key and a 'values' key (a list of integers), returns a list of 'team' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'team' to the result list.",
"Return the result list."
] | def teams_over_total_64(records):
return [row["team"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_team_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
result[key] = total
return result |
task_code | Write a Python function that takes a list of group strings, strips leading/trailing whitespace and converts each to lowercase, keeps only those with length at least 8, and returns a dictionary counting occurrences of each normalized string. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each group, strip and lowercase it.",
"If the cleaned string length is >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_groups_lower_8(groups):
counts = {}
for group in groups:
cleaned = group.strip().lower()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those where the 'weight' key is <= 24, sorts the kept records by 'weight' in ascending order, and returns a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 24.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'label' value from each sorted record into a new list.",
"Return the list of labels."
] | def select_labels_by_weight_24_ascending(records):
kept = [row for row in records if row["weight"] <= 24]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each with 'group' and 'points' keys, keeps only entries where points >= 2, sums the points for each distinct group, and returns a dictionary mapping group to total points. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if points >= 2, add the points to the total for its group.",
"Return the totals dictionary."
] | def total_points_by_group_min_2(records):
totals = {}
for row in records:
if row["points"] >= 2:
group = row["group"]
totals[group] = totals.get(group, 0) + row["points"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each with 'group' and 'points' keys, computes the average points per group, keeps only those averages that are at least 12, and returns a dictionary mapping group to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total points per group, one for count per group.",
"Iterate over each record, updating totals and counts for its group.",
"Compute the average for each group by dividing total by count.",
"Return a dictionary of group to average only for averages >= 12."
] | def qualifying_points_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["points"]
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, compares each pair of values using a margin of 18, and returns a dictionary with counts for 'first_ahead' (first > second by more than 18), 'second_ahead' (second > first by more than 18), and 'within_margin' (otherwise). Do not mutate the input lists. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, check if left - right > 18, then increment 'first_ahead'; else if right - left > 18, increment 'second_ahead'; else increment 'within_margin'.",
"Return the ... | def compare_pairs_with_margin_18_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 18:
counts["first_ahead"] += 1
elif right - left > 18:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2 and adds 3 to each kept integer, preserving the order of rows and elements, and returns the resulting nested list. Do not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list that includes value + 3 for each value >= 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_2_3_2(rows):
return [[value + 3 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each with a 'group' key and a 'values' key (a list of integers), returns a list of 'group' values for which the sum of the integers in 'values' exceeds 64, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 64, append the 'group' to the result list.",
"Return the result list."
] | def groups_over_total_64(records):
return [row["group"] for row in records if sum(row["values"]) > 64] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 14, and returns a new dictionary with those key-total pairs. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 14, add the key-total pair to the result; return the result."
] | def combine_group_counts_min_14(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 14:
result[key] = total
return result |
task_code | Write a Python function that takes a list of tag strings, strips leading/trailing whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_upper_8(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'rating' key <= 25, sorts the kept records by 'rating' in ascending order, and returns a list of the 'title' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where rating <= 25.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'title' value from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_rating_25_ascending(records):
kept = [row for row in records if row["rating"] <= 25]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'tag' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each tag, returning a dictionary mapping each tag to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its tag.",
"Return the totals dictionary."
] | def total_cost_by_tag_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'tag' and 'cost' keys, computes the average cost per tag, and returns a dictionary mapping each tag to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per tag, one for count per tag.",
"Iterate over each record, updating totals and counts for its tag.",
"Compute the average for each tag as total/count.",
"Return a dictionary of tags whose average is >= 12."
] | def qualifying_cost_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
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] >= 12... |
task_code | Write a Python function that takes two equal-length lists of integers, compares each pair of values (one from each list at the same position) using a margin of 19, and returns a dictionary with counts for 'first_ahead' (first > second by more than 19), 'second_ahead' (second > first by more than 19), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_19_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 19:
counts["first_ahead"] += 1
elif right - left > 19:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers >= 2 and multiplies each kept integer by 4, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values >= 2 and multiplies each by 4.",
"Append the transformed inner list to the result.",
"Return the result."
] | def transform_rows_0_4_2(rows):
return [[value * 4 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'tag' and 'values' (a list of integers) keys, and returns a list of 'tag' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'tag' to the result.",
"Return the result list."
] | def tags_over_total_65(records):
return [row["tag"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer 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 at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_tag_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips leading/trailing whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_upper_8(labels):
counts = {}
for label in labels:
cleaned = label.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'rating' key <= 25, sorts the kept records by 'rating' in ascending order, and returns a list of the 'name' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where rating <= 25.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'name' value from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_rating_25_ascending(records):
kept = [row for row in records if row["rating"] <= 25]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each label, returning a dictionary mapping each label to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its label.",
"Return the totals dictionary."
] | def total_cost_by_label_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
group = row["label"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'cost' keys, computes the average cost per label, and returns a dictionary mapping each label to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per label, one for count per label.",
"Iterate over each record, updating totals and counts for its label.",
"Compute the average for each label as total/count.",
"Return a dictionary of labels whose average is >= 12."
] | def qualifying_cost_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
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 each pair of values (one from each list at the same position) using a margin of 20, and returns a dictionary with counts for 'first_ahead' (first > second by more than 20), 'second_ahead' (second > first by more than 20), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_20_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 20:
counts["first_ahead"] += 1
elif right - left > 20:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers greater than 2, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values > 2.",
"Append the filtered inner list to the result.",
"Return the result."
] | def transform_rows_1_4_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'values' (a list of integers) keys, and returns a list of 'label' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'label' to the result.",
"Return the result list."
] | def labels_over_total_65(records):
return [row["label"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer 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 at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_label_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of status strings, strips leading/trailing whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each status, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_upper_8(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'rating' key <= 25, sorts the kept records by 'rating' in ascending order, and returns a list of the 'identifier' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where rating <= 25.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'identifier' value from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_rating_25_ascending(records):
kept = [row for row in records if row["rating"] <= 25]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each status, returning a dictionary mapping each status to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its status.",
"Return the totals dictionary."
] | def total_cost_by_status_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
group = row["status"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'cost' keys, computes the average cost per status, and returns a dictionary mapping each status to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per status, one for count per status.",
"Iterate over each record, updating totals and counts for its status.",
"Compute the average for each status as total/count.",
"Return a dictionary of statuses whose average is >= 12."
] | def qualifying_cost_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
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 each pair of values (one from each list at the same position) using a margin of 21, and returns a dictionary with counts for 'first_ahead' (first > second by more than 21), 'second_ahead' (second > first by more than 21), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_21_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 21:
counts["first_ahead"] += 1
elif right - left > 21:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers >= 2 and adds 4 to each kept integer, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values >= 2 and adds 4 to each.",
"Append the transformed inner list to the result.",
"Return the result."
] | def transform_rows_2_4_2(rows):
return [[value + 4 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'values' (a list of integers) keys, and returns a list of 'status' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'status' to the result.",
"Return the result list."
] | def statuss_over_total_65(records):
return [row["status"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer 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 at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_status_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each category, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_8(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'rating' key <= 25, sorts the kept records by 'rating' in ascending order, and returns a list of the 'label' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where rating <= 25.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'label' value from each sorted record into a new list.",
"Return the list of labels."
] | def select_labels_by_rating_25_ascending(records):
kept = [row for row in records if row["rating"] <= 25]
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 with 'category' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each category, returning a dictionary mapping each category to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its category.",
"Return the totals dictionary."
] | def total_cost_by_category_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
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 with 'category' and 'cost' keys, computes the average cost per category, and returns a dictionary mapping each category to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per category, one for count per category.",
"Iterate over each record, updating totals and counts for its category.",
"Compute the average for each category as total/count.",
"Return a dictionary of categories whose average is >= 12."
] | 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 each pair of values (one from each list at the same position) using a margin of 22, and returns a dictionary with counts for 'first_ahead' (first > second by more than 22), 'second_ahead' (second > first by more than 22), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_22_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 22:
counts["first_ahead"] += 1
elif right - left > 22:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers >= 2 and multiplies each kept integer by 5, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values >= 2 and multiplies each by 5.",
"Append the transformed inner list to the result.",
"Return the result."
] | def transform_rows_0_5_2(rows):
return [[value * 5 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'values' (a list of integers) keys, and returns a list of 'category' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'category' to the result.",
"Return the result list."
] | def categorys_over_total_65(records):
return [row["category"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer 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 at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_category_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
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 to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_upper_8(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'score' key <= 25, sorts the kept records by 'score' in ascending order, and returns a list of the 'title' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where score <= 25.",
"Sort the filtered list by score in ascending order.",
"Extract the 'title' value from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_score_25_ascending(records):
kept = [row for row in records if row["score"] <= 25]
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 with 'topic' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each topic, returning a dictionary mapping each topic to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its topic.",
"Return the totals dictionary."
] | def total_cost_by_topic_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
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 with 'topic' and 'cost' keys, computes the average cost per topic, and returns a dictionary mapping each topic to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per topic, one for count per topic.",
"Iterate over each record, updating totals and counts for its topic.",
"Compute the average for each topic as total/count.",
"Return a dictionary of topics whose average is >= 12."
] | 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 each pair of values (one from each list at the same position) using a margin of 23, and returns a dictionary with counts for 'first_ahead' (first > second by more than 23), 'second_ahead' (second > first by more than 23), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_23_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 23:
counts["first_ahead"] += 1
elif right - left > 23:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers greater than 2, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values > 2.",
"Append the filtered inner list to the result.",
"Return the result."
] | def transform_rows_1_5_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'topic' and 'values' (a list of integers) keys, and returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'topic' to the result.",
"Return the result list."
] | def topics_over_total_65(records):
return [row["topic"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer 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 at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_topic_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.