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 group strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 11. Return a dictionary mapping each such normalized string to its co... | [
"Initialize an empty dictionary for counts.",
"Iterate over each group string, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 11, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_upper_11(groups):
counts = {}
for group in groups:
cleaned = group.strip().upper()
if len(cleaned) >= 11:
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 'label', filters to keep only those where 'score' is <= 27, sorts the kept records by 'score' in ascending order, and returns a list of the 'label' values in that sorted order. Do not mutate the input list. | [
"Create a new list containing only records with score <= 27.",
"Sort that list by the 'score' key in ascending order.",
"Extract the 'label' values from the sorted list into a new list.",
"Return the list of labels."
] | def select_labels_by_score_27_ascending(records):
kept = [row for row in records if row["score"] <= 27]
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, each with keys 'group' and 'cost', filters to keep only entries where 'cost' is at least 3, and then sums the 'cost' values grouped by 'group'. Return a dictionary mapping each group to its total cost. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 3, add the cost to the group's running total.",
"Return the totals dictionary."
] | def total_cost_by_group_min_3(records):
totals = {}
for row in records:
if row["cost"] >= 3:
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, each with keys 'group' and 'cost', computes the average cost per group, and returns a dictionary mapping each group to its average cost, but only for groups whose average cost is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total cost per group, one for count per group.",
"Iterate over each record, updating totals and counts for the group.",
"Compute the average for each group as total divided by count.",
"Return a dictionary of groups whose average is >= 13."
] | 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 lists of integers, compares each pair of values using a margin of 74, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over pairs using zip; for each pair, compute the difference.",
"If first minus second > 74, increment 'first_ahead'; else if second minus first > 74, increment 'second_ahead'; else increment 'within_margin'.",
"Return the dictionary."
] | def compare_pairs_with_margin_74_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 74:
counts["first_ahead"] += 1
elif right - left > 74:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), and for each row, retains only integers that are greater than 3, preserving the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"For each row in the input, create a new list by iterating over its elements.",
"For each element, if it is > 3, append it to the new row list.",
"Append the new row to the result and return the result."
] | def transform_rows_1_3_3(rows):
return [[value for value in row if value > 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'group' and 'values' (a list of integers), and returns a list of 'group' values for which the sum of the integers in 'values' exceeds 71, preserving the original order. Do not mutate the input list. | [
"Initialize an empty list for selected groups.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 71, append the 'group' to the result list.",
"Return the result list."
] | def groups_over_total_71(records):
return [row["group"] for row in records if sum(row["values"]) > 71] |
task_code | Write a Python function that takes two dictionaries mapping group names 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 21. Do not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 21, add key: total to result.",
"Return the result dictionary."
] | def combine_group_counts_min_21(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 21:
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 complete string to lowercase, then counts how many times each normalized string appears, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its coun... | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag string, strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_lower_12(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'title', filters to keep only those where 'priority' is <= 27, sorts the kept records by 'priority' in ascending order, and returns a list of the 'title' values in that sorted order. Do not mutate the input list. | [
"Create a new list containing only records with priority <= 27.",
"Sort that list by the 'priority' key in ascending order.",
"Extract the 'title' values from the sorted list into a new list.",
"Return the list of titles."
] | def select_titles_by_priority_27_ascending(records):
kept = [row for row in records if row["priority"] <= 27]
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, each with keys 'tag' and 'sales', filters to keep only entries where 'sales' is at least 3, and then sums the 'sales' values grouped by 'tag'. Return a dictionary mapping each tag to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if sales >= 3, add the sales to the tag's running total.",
"Return the totals dictionary."
] | def total_sales_by_tag_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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, each with keys 'tag' and 'sales', computes the average sales per tag, and returns a dictionary mapping each tag to its average sales, but only for tags whose average sales is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per tag, one for count per tag.",
"Iterate over each record, updating totals and counts for the tag.",
"Compute the average for each tag as total divided by count.",
"Return a dictionary of tags whose average is >= 13."
] | 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 lists of integers, compares each pair of values using a margin of 75, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over pairs using zip; for each pair, compute the difference.",
"If first minus second > 75, increment 'first_ahead'; else if second minus first > 75, increment 'second_ahead'; else increment 'within_margin'.",
"Return the dictionary."
] | def compare_pairs_with_margin_75_1(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 (list of rows), and for each row, retains only integers that are at least 3 and adds 3 to each retained integer, preserving the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"For each row in the input, create a new list by iterating over its elements.",
"For each element, if it is >= 3, append element + 3 to the new row list.",
"Append the new row to the result and return the result."
] | def transform_rows_2_3_3(rows):
return [[value + 3 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'tag' and 'values' (a list of integers), and returns a list of 'tag' values for which the sum of the integers in 'values' exceeds 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty list for selected tags.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 72, append the 'tag' to the result list.",
"Return the result list."
] | def tags_over_total_72(records):
return [row["tag"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping tag names 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 22. Do not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 22, add key: total to result.",
"Return the result dictionary."
] | def combine_tag_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its co... | [
"Initialize an empty dictionary for counts.",
"Iterate over each label string, strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_lower_12(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'name', filters to keep only those where 'priority' is <= 27, sorts the kept records by 'priority' in ascending order, and returns a list of the 'name' values in that sorted order. Do not mutate the input list. | [
"Create a new list containing only records with priority <= 27.",
"Sort that list by the 'priority' key in ascending order.",
"Extract the 'name' values from the sorted list into a new list.",
"Return the list of names."
] | def select_names_by_priority_27_ascending(records):
kept = [row for row in records if row["priority"] <= 27]
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, each with keys 'label' and 'sales', filters to keep only entries where 'sales' is at least 3, and then sums the 'sales' values grouped by 'label'. Return a dictionary mapping each label to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if sales >= 3, add the sales to the label's running total.",
"Return the totals dictionary."
] | def total_sales_by_label_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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, each with keys 'label' and 'sales', computes the average sales per label, and returns a dictionary mapping each label to its average sales, but only for labels whose average sales is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per label, one for count per label.",
"Iterate over each record, updating totals and counts for the label.",
"Compute the average for each label as total divided by count.",
"Return a dictionary of labels whose average is >= 13."
] | 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 lists of integers, compares each pair of values using a margin of 76, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over pairs using zip; for each pair, compute the difference.",
"If first minus second > 76, increment 'first_ahead'; else if second minus first > 76, increment 'second_ahead'; else increment 'within_margin'.",
"Return the dictionary."
] | def compare_pairs_with_margin_76_1(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 (list of rows), and for each row, retains only integers that are at least 3 and multiplies each retained integer by 4, preserving the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"For each row in the input, create a new list by iterating over its elements.",
"For each element, if it is >= 3, append element * 4 to the new row list.",
"Append the new row to the result and return the result."
] | def transform_rows_0_4_3(rows):
return [[value * 4 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'label' and 'values' (a list of integers), and returns a list of 'label' values for which the sum of the integers in 'values' exceeds 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty list for selected labels.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 72, append the 'label' to the result list.",
"Return the result list."
] | def labels_over_total_72(records):
return [row["label"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping label names 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 22. Do not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 22, add key: total to result.",
"Return the result dictionary."
] | def combine_label_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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 complete string to lowercase, then counts how many times each normalized string appears, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its c... | [
"Initialize an empty dictionary for counts.",
"Iterate over each status string, strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_lower_12(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'identifier', filters to keep only those where 'priority' is <= 27, sorts the kept records by 'priority' in ascending order, and returns a list of the 'identifier' values in that sorted order. Do not mutate the input list. | [
"Create a new list containing only records with priority <= 27.",
"Sort that list by the 'priority' key in ascending order.",
"Extract the 'identifier' values from the sorted list into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_priority_27_ascending(records):
kept = [row for row in records if row["priority"] <= 27]
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, each with keys 'status' and 'sales', filters to keep only entries where 'sales' is at least 3, and then sums the 'sales' values grouped by 'status'. Return a dictionary mapping each status to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if sales >= 3, add the sales to the status's running total.",
"Return the totals dictionary."
] | def total_sales_by_status_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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, each with keys 'status' and 'sales', computes the average sales per status, and returns a dictionary mapping each status to its average sales, but only for statuses whose average sales is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per status, one for count per status.",
"Iterate over each record, updating totals and counts for the status.",
"Compute the average for each status as total divided by count.",
"Return a dictionary of statuses whose average is >= 13."
] | 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 lists of integers, compares each pair of values using a margin of 77, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over pairs using zip; for each pair, compute the difference.",
"If first minus second > 77, increment 'first_ahead'; else if second minus first > 77, increment 'second_ahead'; else increment 'within_margin'.",
"Return the dictionary."
] | def compare_pairs_with_margin_77_1(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 (list of rows), and for each row, retains only integers that are greater than 3, preserving the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"For each row in the input, create a new list by iterating over its elements.",
"For each element, if it is > 3, append it to the new row list.",
"Append the new row to the result and return the result."
] | def transform_rows_1_4_3(rows):
return [[value for value in row if value > 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'values' (a list of integers), and returns a list of 'status' values for which the sum of the integers in 'values' exceeds 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty list for selected statuses.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 72, append the 'status' to the result list.",
"Return the result list."
] | def statuss_over_total_72(records):
return [row["status"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping status names 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 22. Do not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 22, add key: total to result.",
"Return the result dictionary."
] | def combine_status_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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 complete string to lowercase, then counts how many times each normalized string appears, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its... | [
"Initialize an empty dictionary for counts.",
"Iterate over each category string, strip whitespace and convert to lowercase.",
"If the cleaned string length is at least 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_lower_12(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'label', filters to keep only those where 'priority' is <= 27, sorts the kept records by 'priority' in ascending order, and returns a list of the 'label' values in that sorted order. Do not mutate the input list. | [
"Create a new list containing only records with priority <= 27.",
"Sort that list by the 'priority' key in ascending order.",
"Extract the 'label' values from the sorted list into a new list.",
"Return the list of labels."
] | def select_labels_by_priority_27_ascending(records):
kept = [row for row in records if row["priority"] <= 27]
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, each with keys 'category' and 'sales', filters to keep only entries where 'sales' is at least 3, and then sums the 'sales' values grouped by 'category'. Return a dictionary mapping each category to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if sales >= 3, add the sales to the category's running total.",
"Return the totals dictionary."
] | def total_sales_by_category_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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, each with keys 'category' and 'sales', computes the average sales per category, and returns a dictionary mapping each category to its average sales, but only for categories whose average sales is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per category, one for count per category.",
"Iterate over each record, updating totals and counts for the category.",
"Compute the average for each category as total divided by count.",
"Return a dictionary of categories whose average is >= 13."
] | 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 lists of integers, compares each pair of values using a margin of 78, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists. | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over pairs using zip; for each pair, compute the difference.",
"If first minus second > 78, increment 'first_ahead'; else if second minus first > 78, increment 'second_ahead'; else increment 'within_margin'.",
"Return the dictionary."
] | def compare_pairs_with_margin_78_1(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 (list of rows), and for each row, retains only integers that are at least 3 and adds 4 to each retained integer, preserving the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"For each row in the input, create a new list by iterating over its elements.",
"For each element, if it is >= 3, append element + 4 to the new row list.",
"Append the new row to the result and return the result."
] | def transform_rows_2_4_3(rows):
return [[value + 4 for value in row if value >= 3] 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 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty list for selected categories.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 72, append the 'category' to the result list.",
"Return the result list."
] | def categorys_over_total_72(records):
return [row["category"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping category names 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 22. Do not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 22, add key: total to result.",
"Return the result dictionary."
] | def combine_category_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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, then counts how many times each normalized string appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not mu... | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_lower_12(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'quality' and 'title'. Keep only those records where 'quality' is <= 27, then sort the kept records by 'quality' in ascending order. Return a list of the 'title' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['quality'] <= 27.",
"Sort the filtered list by 'quality' in ascending order.",
"Extract the 'title' values from the sorted list.",
"Return the list of titles."
] | def select_titles_by_quality_27_ascending(records):
kept = [row for row in records if row["quality"] <= 27]
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 with keys 'topic' and 'sales'. Keep only entries where 'sales' is at least 3, then sum the 'sales' values grouped by 'topic'. Return a dictionary mapping each topic to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['sales'] >= 3, add row['sales'] to the total for row['topic'].",
"Return the totals dictionary."
] | def total_sales_by_topic_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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 with keys 'topic' and 'sales'. Compute the average sales per topic across all records. Return a dictionary mapping each topic to its average, but only include topics where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per topic, one for count per topic.",
"Iterate over each record: update totals and counts for the record's topic.",
"Compute the average for each topic as total / count.",
"Return a dictionary of topics whose average >= 13."
] | 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. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 79 greater than the second, how many have the second more than 79 greater than the first, and how many are within 79 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 79.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_79_1(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 (list of rows). For each row, keep only integers that are at least 3, and multiply each kept integer by 5. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values >= 3 and multiply them by 5.",
"Append the transformed row to result and return result."
] | def transform_rows_0_5_3(rows):
return [[value * 5 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'values' (where 'values' is a list of integers). Return a list of the 'topic' values for which the sum of the integers in 'values' is greater than 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 72, append row['topic'] to result.",
"Return the result list."
] | def topics_over_total_72(records):
return [row["topic"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 22. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 22, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_topic_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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, then counts how many times each normalized string appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not m... | [
"Initialize an empty dictionary for counts.",
"Iterate over each region string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_lower_12(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'quality' and 'name'. Keep only those records where 'quality' is <= 27, then sort the kept records by 'quality' in ascending order. Return a list of the 'name' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['quality'] <= 27.",
"Sort the filtered list by 'quality' in ascending order.",
"Extract the 'name' values from the sorted list.",
"Return the list of names."
] | def select_names_by_quality_27_ascending(records):
kept = [row for row in records if row["quality"] <= 27]
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 with keys 'region' and 'sales'. Keep only entries where 'sales' is at least 3, then sum the 'sales' values grouped by 'region'. Return a dictionary mapping each region to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['sales'] >= 3, add row['sales'] to the total for row['region'].",
"Return the totals dictionary."
] | def total_sales_by_region_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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 with keys 'region' and 'sales'. Compute the average sales per region across all records. Return a dictionary mapping each region to its average, but only include regions where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per region, one for count per region.",
"Iterate over each record: update totals and counts for the record's region.",
"Compute the average for each region as total / count.",
"Return a dictionary of regions whose average >= 13."
] | 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. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 80 greater than the second, how many have the second more than 80 greater than the first, and how many are within 80 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 80.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_80_1(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 (list of rows). For each row, keep only integers that are greater than 3. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values > 3.",
"Append the filtered row to result and return result."
] | def transform_rows_1_5_3(rows):
return [[value for value in row if value > 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'values' (where 'values' is a list of integers). Return a list of the 'region' values for which the sum of the integers in 'values' is greater than 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 72, append row['region'] to result.",
"Return the result list."
] | def regions_over_total_72(records):
return [row["region"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 22. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 22, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_region_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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, then counts how many times each normalized string appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not mut... | [
"Initialize an empty dictionary for counts.",
"Iterate over each team string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_lower_12(teams):
counts = {}
for team in teams:
cleaned = team.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'quality' and 'identifier'. Keep only those records where 'quality' is <= 27, then sort the kept records by 'quality' in ascending order. Return a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['quality'] <= 27.",
"Sort the filtered list by 'quality' in ascending order.",
"Extract the 'identifier' values from the sorted list.",
"Return the list of identifiers."
] | def select_identifiers_by_quality_27_ascending(records):
kept = [row for row in records if row["quality"] <= 27]
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 with keys 'team' and 'sales'. Keep only entries where 'sales' is at least 3, then sum the 'sales' values grouped by 'team'. Return a dictionary mapping each team to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['sales'] >= 3, add row['sales'] to the total for row['team'].",
"Return the totals dictionary."
] | def total_sales_by_team_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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 with keys 'team' and 'sales'. Compute the average sales per team across all records. Return a dictionary mapping each team to its average, but only include teams where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per team, one for count per team.",
"Iterate over each record: update totals and counts for the record's team.",
"Compute the average for each team as total / count.",
"Return a dictionary of teams whose average >= 13."
] | 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. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 81 greater than the second, how many have the second more than 81 greater than the first, and how many are within 81 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 81.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_81_1(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 (list of rows). For each row, keep only integers that are at least 3, and add 5 to each kept integer. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values >= 3 and add 5 to them.",
"Append the transformed row to result and return result."
] | def transform_rows_2_5_3(rows):
return [[value + 5 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (where 'values' is a list of integers). Return a list of the 'team' values for which the sum of the integers in 'values' is greater than 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 72, append row['team'] to result.",
"Return the result list."
] | def teams_over_total_72(records):
return [row["team"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 22. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 22, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_team_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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, then counts how many times each normalized string appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not mu... | [
"Initialize an empty dictionary for counts.",
"Iterate over each group string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_lower_12(groups):
counts = {}
for group in groups:
cleaned = group.strip().lower()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'quality' and 'label'. Keep only those records where 'quality' is <= 27, then sort the kept records by 'quality' in ascending order. Return a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['quality'] <= 27.",
"Sort the filtered list by 'quality' in ascending order.",
"Extract the 'label' values from the sorted list.",
"Return the list of labels."
] | def select_labels_by_quality_27_ascending(records):
kept = [row for row in records if row["quality"] <= 27]
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 with keys 'group' and 'sales'. Keep only entries where 'sales' is at least 3, then sum the 'sales' values grouped by 'group'. Return a dictionary mapping each group to its total sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['sales'] >= 3, add row['sales'] to the total for row['group'].",
"Return the totals dictionary."
] | def total_sales_by_group_min_3(records):
totals = {}
for row in records:
if row["sales"] >= 3:
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 with keys 'group' and 'sales'. Compute the average sales per group across all records. Return a dictionary mapping each group to its average, but only include groups where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per group, one for count per group.",
"Iterate over each record: update totals and counts for the record's group.",
"Compute the average for each group as total / count.",
"Return a dictionary of groups whose average >= 13."
] | 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]... |
task_code | Write a Python function that takes two equal-length lists of integers. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 82 greater than the second, how many have the second more than 82 greater than the first, and how many are within 82 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 82.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_82_1(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 (list of rows). For each row, keep only integers that are at least 3, and multiply each kept integer by 6. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values >= 3 and multiply them by 6.",
"Append the transformed row to result and return result."
] | def transform_rows_0_6_3(rows):
return [[value * 6 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'group' and 'values' (where 'values' is a list of integers). Return a list of the 'group' values for which the sum of the integers in 'values' is greater than 72, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 72, append row['group'] to result.",
"Return the result list."
] | def groups_over_total_72(records):
return [row["group"] for row in records if sum(row["values"]) > 72] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 22. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 22, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_group_counts_min_22(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 22:
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 appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not muta... | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_upper_12(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().upper()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'title'. Keep only those records where 'rank' is <= 27, then sort the kept records by 'rank' in ascending order. Return a list of the 'title' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['rank'] <= 27.",
"Sort the filtered list by 'rank' in ascending order.",
"Extract the 'title' values from the sorted list.",
"Return the list of titles."
] | def select_titles_by_rank_27_ascending(records):
kept = [row for row in records if row["rank"] <= 27]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'tag' and 'items'. Keep only entries where 'items' is at least 3, then sum the 'items' values grouped by 'tag'. Return a dictionary mapping each tag to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['items'] >= 3, add row['items'] to the total for row['tag'].",
"Return the totals dictionary."
] | def total_items_by_tag_min_3(records):
totals = {}
for row in records:
if row["items"] >= 3:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["items"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'tag' and 'items'. Compute the average items per tag across all records. Return a dictionary mapping each tag to its average, but only include tags where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per tag, one for count per tag.",
"Iterate over each record: update totals and counts for the record's tag.",
"Compute the average for each tag as total / count.",
"Return a dictionary of tags whose average >= 13."
] | def qualifying_items_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["items"]
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. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 83 greater than the second, how many have the second more than 83 greater than the first, and how many are within 83 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 83.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_83_1(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 (list of rows). For each row, keep only integers that are greater than 3. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values > 3.",
"Append the filtered row to result and return result."
] | def transform_rows_1_6_3(rows):
return [[value for value in row if value > 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'tag' and 'values' (where 'values' is a list of integers). Return a list of the 'tag' values for which the sum of the integers in 'values' is greater than 73, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 73, append row['tag'] to result.",
"Return the result list."
] | def tags_over_total_73(records):
return [row["tag"] for row in records if sum(row["values"]) > 73] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 23. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 23, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_tag_counts_min_23(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 23:
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 appears, but only includes those with length at least 12. Return a dictionary mapping each qualifying normalized string to its count. Do not mu... | [
"Initialize an empty dictionary for counts.",
"Iterate over each label string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_upper_12(labels):
counts = {}
for label in labels:
cleaned = label.strip().upper()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'name'. Keep only those records where 'rank' is <= 27, then sort the kept records by 'rank' in ascending order. Return a list of the 'name' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep rows where row['rank'] <= 27.",
"Sort the filtered list by 'rank' in ascending order.",
"Extract the 'name' values from the sorted list.",
"Return the list of names."
] | def select_names_by_rank_27_ascending(records):
kept = [row for row in records if row["rank"] <= 27]
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 with keys 'label' and 'items'. Keep only entries where 'items' is at least 3, then sum the 'items' values grouped by 'label'. Return a dictionary mapping each label to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if row['items'] >= 3, add row['items'] to the total for row['label'].",
"Return the totals dictionary."
] | def total_items_by_label_min_3(records):
totals = {}
for row in records:
if row["items"] >= 3:
group = row["label"]
totals[group] = totals.get(group, 0) + row["items"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'label' and 'items'. Compute the average items per label across all records. Return a dictionary mapping each label to its average, but only include labels where the average is at least 13. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per label, one for count per label.",
"Iterate over each record: update totals and counts for the record's label.",
"Compute the average for each label as total / count.",
"Return a dictionary of labels whose average >= 13."
] | def qualifying_items_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["items"]
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. Compare each pair of values (one from each list at the same index). Count how many pairs have the first value more than 84 greater than the second, how many have the second more than 84 greater than the first, and how many are within 84 of each othe... | [
"Initialize counts dictionary with three keys set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into based on the difference and margin of 84.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_84_1(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 (list of rows). For each row, keep only integers that are at least 3, and add 6 to each kept integer. Return a new nested list with the same structure (order of rows and order within rows preserved). Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each row in the input.",
"For each row, build a new list: keep values >= 3 and add 6 to them.",
"Append the transformed row to result and return result."
] | def transform_rows_2_6_3(rows):
return [[value + 6 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'label' and 'values' (where 'values' is a list of integers). Return a list of the 'label' values for which the sum of the integers in 'values' is greater than 73, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in order.",
"If sum(row['values']) > 73, append row['label'] to result.",
"Return the result list."
] | def labels_over_total_73(records):
return [row["label"] for row in records if sum(row["values"]) > 73] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts. For each key that appears in either dictionary, compute the sum of its counts (using 0 if missing from one dictionary). Keep only those keys where the total sum is at least 23. Return a new dictionary with those keys and their sums. Do ... | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 23, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_label_counts_min_23(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 23:
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 entire string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its cou... | [
"Initialize an empty dictionary for counts.",
"Loop over each status string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_upper_12(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().upper()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'identifier'. Keep only those records where 'rank' is <= 27, then sort the kept records by 'rank' in ascending order. Finally, return a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 27.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return that list."
] | def select_identifiers_by_rank_27_ascending(records):
kept = [row for row in records if row["rank"] <= 27]
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 keys 'status' and 'items'. Keep only those entries where 'items' is at least 3, then sum the 'items' values grouped by 'status'. Return a dictionary mapping each status to the total items from qualifying entries. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 3, add items to the total for its status.",
"Return the totals dictionary."
] | def total_items_by_status_min_3(records):
totals = {}
for row in records:
if row["items"] >= 3:
group = row["status"]
totals[group] = totals.get(group, 0) + row["items"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'items'. Compute the average items per status across all records. Then keep only those averages that are at least 13. Return a dictionary mapping each qualifying status to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per status, one for count per status.",
"Loop over each record: accumulate items and increment count for its status.",
"Compute average for each status by dividing total by count.",
"Return a dictionary of status -> average for those averages >= 13."
] | def qualifying_items_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["items"]
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. Compare each pair of values (one from each list at the same index) using a margin of 85. Count how many pairs satisfy: first value minus second value > 85 (first_ahead), second value minus first value > 85 (second_ahead), or neither (within_margin).... | [
"Initialize a dictionary with three keys set to 0.",
"Loop over paired elements using zip.",
"For each pair, determine which condition holds and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_85_1(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 (list of rows, each row is a list of integers). For each row, keep only integers that are at least 3, and multiply each kept integer by 7. Preserve the row structure and order. Return a new nested list. Do not mutate the input. | [
"Initialize an empty list for the result.",
"Loop over each row: create a new row by filtering values >= 3 and multiplying each by 7.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_0_7_3(rows):
return [[value * 7 for value in row if value >= 3] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'values' (a list of integers). Return a list of 'status' values for those records where the sum of the integers in 'values' exceeds 73. Maintain the original order. Do not mutate the input list. | [
"Initialize an empty list for results.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 73, append the 'status' to the result list.",
"Return the result list."
] | def statuss_over_total_73(records):
return [row["status"] for row in records if sum(row["values"]) > 73] |
task_code | Write a Python function that takes two dictionaries mapping status strings to integer counts. For every key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those sums that are at least 23. Return a new dictionary with those keys and sums. Do not mutate the input di... | [
"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 >= 23, add key: total to result. Return result."
] | def combine_status_counts_min_23(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 23:
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 entire string to uppercase, then counts how many times each normalized string appears, but only includes those whose length is at least 12. Return a dictionary mapping each such normalized string to its c... | [
"Initialize an empty dictionary for counts.",
"Loop over each category string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 12, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_12(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
if len(cleaned) >= 12:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'label'. Keep only those records where 'rank' is <= 27, then sort the kept records by 'rank' in ascending order. Finally, return a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 27.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return that list."
] | def select_labels_by_rank_27_ascending(records):
kept = [row for row in records if row["rank"] <= 27]
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 keys 'category' and 'items'. Keep only those entries where 'items' is at least 3, then sum the 'items' values grouped by 'category'. Return a dictionary mapping each category to the total items from qualifying entries. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 3, add items to the total for its category.",
"Return the totals dictionary."
] | def total_items_by_category_min_3(records):
totals = {}
for row in records:
if row["items"] >= 3:
group = row["category"]
totals[group] = totals.get(group, 0) + row["items"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'items'. Compute the average items per category across all records. Then keep only those averages that are at least 13. Return a dictionary mapping each qualifying category to its average. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per category, one for count per category.",
"Loop over each record: accumulate items and increment count for its category.",
"Compute average for each category by dividing total by count.",
"Return a dictionary of category -> average for those averages >= 13."... | def qualifying_items_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["items"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / cou... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.