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 tag strings, strips leading/trailing whitespace and converts each complete string to lowercase, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag in the input list, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_lower_1(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is less than or equal to 20, sorts the kept records by 'rating' in ascending order, returns a list of the 'title' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with rating <= 20.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'title' values from the sorted list.",
"Return the list of titles."
] | def select_titles_by_rating_20_ascending(records):
kept = [row for row in records if row["rating"] <= 20]
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 each containing 'tag' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'tag' value, returns a new dictionary mapping each tag to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its tag.",
"Return the totals dictionary."
] | def total_hours_by_tag_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'tag' and 'hours' keys, computes the average hours per tag, retains only those averages that are at least 10, returns a dictionary mapping each tag to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per tag and one for count per tag.",
"Iterate over records, accumulating total hours and count for each tag.",
"Compute average for each tag as total divided by count.",
"Return a dictionary of tags with average >= 10."
] | def qualifying_hours_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["hours"]
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 0, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_0(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 0:
counts["first_ahead"] += 1
elif right - left > 0:
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 0 within each inner list, multiplies each retained integer by 2, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values >= 0 and multiplying each by 2.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_0_2_0(rows):
return [[value * 2 for value in row if value >= 0] 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 from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'tag' to the result.",
"Return the result list."
] | def tags_over_total_50(records):
return [row["tag"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_tag_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_lower_1(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is less than or equal to 20, sorts the kept records by 'rating' in ascending order, returns a list of the 'name' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with rating <= 20.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'name' values from the sorted list.",
"Return the list of names."
] | def select_names_by_rating_20_ascending(records):
kept = [row for row in records if row["rating"] <= 20]
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 each containing 'label' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'label' value, returns a new dictionary mapping each label to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its label.",
"Return the totals dictionary."
] | def total_hours_by_label_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["label"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'label' and 'hours' keys, computes the average hours per label, retains only those averages that are at least 10, returns a dictionary mapping each label to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per label and one for count per label.",
"Iterate over records, accumulating total hours and count for each label.",
"Compute average for each label as total divided by count.",
"Return a dictionary of labels with average >= 10."
] | def qualifying_hours_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["hours"]
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 1, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 1:
counts["first_ahead"] += 1
elif right - left > 1:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers greater than 0 within each inner list, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values > 0.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_1_2_0(rows):
return [[value for value in row if value > 0] 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 from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'label' to the result.",
"Return the result list."
] | def labels_over_total_50(records):
return [row["label"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_label_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each status, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_lower_1(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is less than or equal to 20, sorts the kept records by 'rating' in ascending order, returns a list of the 'identifier' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with rating <= 20.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'identifier' values from the sorted list.",
"Return the list of identifiers."
] | def select_identifiers_by_rating_20_ascending(records):
kept = [row for row in records if row["rating"] <= 20]
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 each containing 'status' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'status' value, returns a new dictionary mapping each status to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its status.",
"Return the totals dictionary."
] | def total_hours_by_status_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["status"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'status' and 'hours' keys, computes the average hours per status, retains only those averages that are at least 10, returns a dictionary mapping each status to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per status and one for count per status.",
"Iterate over records, accumulating total hours and count for each status.",
"Compute average for each status as total divided by count.",
"Return a dictionary of statuses with average >= 10."
] | def qualifying_hours_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["hours"]
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 2, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_2(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 2:
counts["first_ahead"] += 1
elif right - left > 2:
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 0 within each inner list, adds 2 to each retained integer, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values >= 0 and adding 2 to each.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_2_2_0(rows):
return [[value + 2 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'status' key and a 'values' key that is a list of integers, returns a list of 'status' values from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'status' to the result.",
"Return the result list."
] | def statuss_over_total_50(records):
return [row["status"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_status_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each category, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_lower_1(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is less than or equal to 20, sorts the kept records by 'rating' in ascending order, returns a list of the 'label' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with rating <= 20.",
"Sort the filtered list by rating in ascending order.",
"Extract the 'label' values from the sorted list.",
"Return the list of labels."
] | def select_labels_by_rating_20_ascending(records):
kept = [row for row in records if row["rating"] <= 20]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'category' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'category' value, returns a new dictionary mapping each category to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its category.",
"Return the totals dictionary."
] | def total_hours_by_category_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["category"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'category' and 'hours' keys, computes the average hours per category, retains only those averages that are at least 10, returns a dictionary mapping each category to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per category and one for count per category.",
"Iterate over records, accumulating total hours and count for each category.",
"Compute average for each category as total divided by count.",
"Return a dictionary of categories with average >= 10."
] | def qualifying_hours_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["hours"]
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 3, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_3(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 3:
counts["first_ahead"] += 1
elif right - left > 3:
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 0 within each inner list, multiplies each retained integer by 3, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values >= 0 and multiplying each by 3.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_0_3_0(rows):
return [[value * 3 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'category' key and a 'values' key that is a list of integers, returns a list of 'category' values from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'category' to the result.",
"Return the result list."
] | def categorys_over_total_50(records):
return [row["category"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_category_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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 complete string to lowercase, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_lower_1(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'score' key is less than or equal to 20, sorts the kept records by 'score' in ascending order, returns a list of the 'title' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with score <= 20.",
"Sort the filtered list by score in ascending order.",
"Extract the 'title' values from the sorted list.",
"Return the list of titles."
] | def select_titles_by_score_20_ascending(records):
kept = [row for row in records if row["score"] <= 20]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'topic' value, returns a new dictionary mapping each topic to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its topic.",
"Return the totals dictionary."
] | def total_hours_by_topic_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'hours' keys, computes the average hours per topic, retains only those averages that are at least 10, returns a dictionary mapping each topic to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per topic and one for count per topic.",
"Iterate over records, accumulating total hours and count for each topic.",
"Compute average for each topic as total divided by count.",
"Return a dictionary of topics with average >= 10."
] | def qualifying_hours_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["hours"]
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 4, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_4(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 4:
counts["first_ahead"] += 1
elif right - left > 4:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers greater than 0 within each inner list, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values > 0.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_1_3_0(rows):
return [[value for value in row if value > 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'topic' key and a 'values' key that is a list of integers, returns a list of 'topic' values from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'topic' to the result.",
"Return the result list."
] | def topics_over_total_50(records):
return [row["topic"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_topic_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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 complete string to lowercase, retains only normalized strings with length at least 1, returns a dictionary mapping each normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region, strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_lower_1(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'score' key is less than or equal to 20, sorts the kept records by 'score' in ascending order, returns a list of the 'name' values from the sorted records, and does not mutate the input list. | [
"Filter the list to keep records with score <= 20.",
"Sort the filtered list by score in ascending order.",
"Extract the 'name' values from the sorted list.",
"Return the list of names."
] | def select_names_by_score_20_ascending(records):
kept = [row for row in records if row["score"] <= 20]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'hours' keys, keeps only entries where 'hours' is at least 0, sums the retained hours grouped by the 'region' value, returns a new dictionary mapping each region to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 0, add hours to the total for its region.",
"Return the totals dictionary."
] | def total_hours_by_region_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["region"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'hours' keys, computes the average hours per region, retains only those averages that are at least 10, returns a dictionary mapping each region to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per region and one for count per region.",
"Iterate over records, accumulating total hours and count for each region.",
"Compute average for each region as total divided by count.",
"Return a dictionary of regions with average >= 10."
] | def qualifying_hours_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["hours"]
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 5, counts how many pairs have the first value ahead by more than the margin, how many have the second value ahead by more than the margin, and how many are within the margin, returns a dictionary with k... | [
"Initialize a dictionary with three counters set to 0.",
"Iterate over paired elements using zip.",
"If first minus second > margin, increment first_ahead; else if second minus first > margin, increment second_ahead; else increment within_margin.",
"Return the dictionary."
] | def compare_pairs_with_margin_5(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 5:
counts["first_ahead"] += 1
elif right - left > 5:
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 0 within each inner list, adds 3 to each retained integer, preserves the original row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list by filtering values >= 0 and adding 3 to each.",
"Append the new list to the result.",
"Return the result."
] | def transform_rows_2_3_0(rows):
return [[value + 3 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'region' key and a 'values' key that is a list of integers, returns a list of 'region' values from records where the sum of the integers in 'values' exceeds 50, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 50, append its 'region' to the result.",
"Return the result list."
] | def regions_over_total_50(records):
return [row["region"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the values over the union of keys (treating missing keys as 0), retains only totals that are at least 0, returns a new dictionary with those totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"For each key in the union of both dictionaries, compute total = first.get(key,0) + second.get(key,0).",
"If total >= 0, add key and total to result.",
"Return the result."
] | def combine_region_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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 complete string to lowercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The funct... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each team string in the input list: strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_lower_1(teams):
counts = {}
for team in teams:
cleaned = team.strip().lower()
if len(cleaned) >= 1:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'score' and 'identifier', keeps only those records where 'score' is <= 20, sorts the kept records by 'score' in ascending order, and returns a list of the 'identifier' values from the sorted records. The function must not mutate the input list. | [
"Filter the list to keep records with score <= 20.",
"Sort the filtered list by the 'score' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return that list."
] | def select_identifiers_by_score_20_ascending(records):
kept = [row for row in records if row["score"] <= 20]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'hours', keeps only those entries where 'hours' is >= 0, sums the 'hours' values grouped by the 'team' key, and returns a new dictionary mapping each team to its total hours. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if hours >= 0, add hours to the total for its team.",
"Return the totals dictionary."
] | def total_hours_by_team_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["team"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'hours', computes the average hours per team, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying team to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total hours per team, one for count per team.",
"Iterate over each record: add hours to the team's total and increment its count.",
"Compute the average for each team (total / count).",
"Return a dictionary of teams whose average is >= 10."
] | def qualifying_hours_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["hours"]
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 corresponding values (one from each list) using a margin of 6, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 6, 'second_ahead' for pairs where the second minus th... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_6(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 6:
counts["first_ahead"] += 1
elif right - left > 6:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), retains only integers that are >= 0 within each row, multiplies each retained integer by 4, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are >= 0 and multiply each by 4.",
"Collect these transformed rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_0_4_0(rows):
return [[value * 4 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (a list of integers), and returns a list of the 'team' values from those records where the sum of the integers in 'values' exceeds 50, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 50, append the record's 'team' to the result.",
"Return the result list."
] | def teams_over_total_50(records):
return [row["team"] for row in records if sum(row["values"]) > 50] |
task_code | Write a Python function that takes two dictionaries mapping team names to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those totals that are >= 0, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 0, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_team_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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 complete string to lowercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The func... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each group string in the input list: strip whitespace and convert to lowercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_lower_1(groups):
counts = {}
for group in groups:
cleaned = group.strip().lower()
if len(cleaned) >= 1:
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', keeps only those records where 'score' is <= 20, sorts the kept records by 'score' in ascending order, and returns a list of the 'label' values from the sorted records. The function must not mutate the input list. | [
"Filter the list to keep records with score <= 20.",
"Sort the filtered list by the 'score' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return that list."
] | def select_labels_by_score_20_ascending(records):
kept = [row for row in records if row["score"] <= 20]
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 'hours', keeps only those entries where 'hours' is >= 0, sums the 'hours' values grouped by the 'group' key, and returns a new dictionary mapping each group to its total hours. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if hours >= 0, add hours to the total for its group.",
"Return the totals dictionary."
] | def total_hours_by_group_min_0(records):
totals = {}
for row in records:
if row["hours"] >= 0:
group = row["group"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'group' and 'hours', computes the average hours per group, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying group to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total hours per group, one for count per group.",
"Iterate over each record: add hours to the group's total and increment its count.",
"Compute the average for each group (total / count).",
"Return a dictionary of groups whose average is >= 10."
] | def qualifying_hours_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["hours"]
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 corresponding values (one from each list) using a margin of 7, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 7, 'second_ahead' for pairs where the second minus th... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_7(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 7:
counts["first_ahead"] += 1
elif right - left > 7:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), keeps only integers that are greater than 0 within each row, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are > 0.",
"Collect these filtered rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_1_4_0(rows):
return [[value for value in row if value > 0] 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 the 'group' values from those records where the sum of the integers in 'values' exceeds 50, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 50, append the record's 'group' to the result.",
"Return the result list."
] | def groups_over_total_50(records):
return [row["group"] for row in records if sum(row["values"]) > 50] |
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), keeps only those totals that are >= 0, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 0, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_group_counts_min_0(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 0:
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 uppercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The functi... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each tag string in the input list: strip whitespace and convert to uppercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_upper_1(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().upper()
if len(cleaned) >= 1:
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', keeps only those records where 'priority' is <= 20, sorts the kept records by 'priority' in ascending order, and returns a list of the 'title' values from the sorted records. The function must not mutate the input list. | [
"Filter the list to keep records with priority <= 20.",
"Sort the filtered list by the 'priority' key in ascending order.",
"Extract the 'title' values from the sorted records into a new list.",
"Return that list."
] | def select_titles_by_priority_20_ascending(records):
kept = [row for row in records if row["priority"] <= 20]
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 'units', keeps only those entries where 'units' is >= 0, sums the 'units' values grouped by the 'tag' key, and returns a new dictionary mapping each tag to its total units. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if units >= 0, add units to the total for its tag.",
"Return the totals dictionary."
] | def total_units_by_tag_min_0(records):
totals = {}
for row in records:
if row["units"] >= 0:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'tag' and 'units', computes the average units per tag, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying tag to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total units per tag, one for count per tag.",
"Iterate over each record: add units to the tag's total and increment its count.",
"Compute the average for each tag (total / count).",
"Return a dictionary of tags whose average is >= 10."
] | def qualifying_units_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["units"]
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 corresponding values (one from each list) using a margin of 8, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 8, 'second_ahead' for pairs where the second minus th... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_8(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 8:
counts["first_ahead"] += 1
elif right - left > 8:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), retains only integers that are >= 0 within each row, adds 4 to each retained integer, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are >= 0 and add 4 to each.",
"Collect these transformed rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_2_4_0(rows):
return [[value + 4 for value in row if value >= 0] 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 the 'tag' values from those records where the sum of the integers in 'values' exceeds 51, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 51, append the record's 'tag' to the result.",
"Return the result list."
] | def tags_over_total_51(records):
return [row["tag"] for row in records if sum(row["values"]) > 51] |
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), keeps only those totals that are >= 1, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 1, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_tag_counts_min_1(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 1:
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 uppercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The func... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each label string in the input list: strip whitespace and convert to uppercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_upper_1(labels):
counts = {}
for label in labels:
cleaned = label.strip().upper()
if len(cleaned) >= 1:
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', keeps only those records where 'priority' is <= 20, sorts the kept records by 'priority' in ascending order, and returns a list of the 'name' values from the sorted records. The function must not mutate the input list. | [
"Filter the list to keep records with priority <= 20.",
"Sort the filtered list by the 'priority' key in ascending order.",
"Extract the 'name' values from the sorted records into a new list.",
"Return that list."
] | def select_names_by_priority_20_ascending(records):
kept = [row for row in records if row["priority"] <= 20]
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 'units', keeps only those entries where 'units' is >= 0, sums the 'units' values grouped by the 'label' key, and returns a new dictionary mapping each label to its total units. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if units >= 0, add units to the total for its label.",
"Return the totals dictionary."
] | def total_units_by_label_min_0(records):
totals = {}
for row in records:
if row["units"] >= 0:
group = row["label"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'label' and 'units', computes the average units per label, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying label to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total units per label, one for count per label.",
"Iterate over each record: add units to the label's total and increment its count.",
"Compute the average for each label (total / count).",
"Return a dictionary of labels whose average is >= 10."
] | def qualifying_units_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["units"]
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 corresponding values (one from each list) using a margin of 9, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 9, 'second_ahead' for pairs where the second minus th... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_9(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 9:
counts["first_ahead"] += 1
elif right - left > 9:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), retains only integers that are >= 0 within each row, multiplies each retained integer by 5, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are >= 0 and multiply each by 5.",
"Collect these transformed rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_0_5_0(rows):
return [[value * 5 for value in row if value >= 0] 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 the 'label' values from those records where the sum of the integers in 'values' exceeds 51, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 51, append the record's 'label' to the result.",
"Return the result list."
] | def labels_over_total_51(records):
return [row["label"] for row in records if sum(row["values"]) > 51] |
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), keeps only those totals that are >= 1, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 1, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_label_counts_min_1(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 1:
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 uppercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The fun... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each status string in the input list: strip whitespace and convert to uppercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_upper_1(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().upper()
if len(cleaned) >= 1:
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', keeps only those records where 'priority' is <= 20, sorts the kept records by 'priority' in ascending order, and returns a list of the 'identifier' values from the sorted records. The function must not mutate the inpu... | [
"Filter the list to keep records with priority <= 20.",
"Sort the filtered list by the 'priority' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return that list."
] | def select_identifiers_by_priority_20_ascending(records):
kept = [row for row in records if row["priority"] <= 20]
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 'units', keeps only those entries where 'units' is >= 0, sums the 'units' values grouped by the 'status' key, and returns a new dictionary mapping each status to its total units. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if units >= 0, add units to the total for its status.",
"Return the totals dictionary."
] | def total_units_by_status_min_0(records):
totals = {}
for row in records:
if row["units"] >= 0:
group = row["status"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'units', computes the average units per status, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying status to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total units per status, one for count per status.",
"Iterate over each record: add units to the status's total and increment its count.",
"Compute the average for each status (total / count).",
"Return a dictionary of statuses whose average is >= 10."
] | def qualifying_units_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["units"]
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 corresponding values (one from each list) using a margin of 10, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 10, 'second_ahead' for pairs where the second minus ... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_10(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 10:
counts["first_ahead"] += 1
elif right - left > 10:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers (list of rows), keeps only integers that are greater than 0 within each row, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are > 0.",
"Collect these filtered rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_1_5_0(rows):
return [[value for value in row if value > 0] 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 the 'status' values from those records where the sum of the integers in 'values' exceeds 51, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 51, append the record's 'status' to the result.",
"Return the result list."
] | def statuss_over_total_51(records):
return [row["status"] for row in records if sum(row["values"]) > 51] |
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), keeps only those totals that are >= 1, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 1, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_status_counts_min_1(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 1:
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 uppercase, keeps only those normalized strings with length at least 1, and returns a dictionary mapping each such normalized string to the number of times it appears in the input. The f... | [
"Initialize an empty dictionary to hold counts.",
"Iterate over each category string in the input list: strip whitespace and convert to uppercase.",
"If the cleaned string has length at least 1, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_1(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
if len(cleaned) >= 1:
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', keeps only those records where 'priority' is <= 20, sorts the kept records by 'priority' in ascending order, and returns a list of the 'label' values from the sorted records. The function must not mutate the input list. | [
"Filter the list to keep records with priority <= 20.",
"Sort the filtered list by the 'priority' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return that list."
] | def select_labels_by_priority_20_ascending(records):
kept = [row for row in records if row["priority"] <= 20]
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 'units', keeps only those entries where 'units' is >= 0, sums the 'units' values grouped by the 'category' key, and returns a new dictionary mapping each category to its total units. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if units >= 0, add units to the total for its category.",
"Return the totals dictionary."
] | def total_units_by_category_min_0(records):
totals = {}
for row in records:
if row["units"] >= 0:
group = row["category"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'units', computes the average units per category, keeps only those averages that are at least 10, and returns a dictionary mapping each qualifying category to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total units per category, one for count per category.",
"Iterate over each record: add units to the category's total and increment its count.",
"Compute the average for each category (total / count).",
"Return a dictionary of categories whose average is >= 10."
] | def qualifying_units_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / cou... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of corresponding values (one from each list) using a margin of 11, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value minus the second exceeds 11, 'second_ahead' for pairs where the second minus ... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements from both lists using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the dictionary."
] | def compare_pairs_with_margin_11(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 (list of rows), retains only integers that are >= 0 within each row, adds 5 to each retained integer, and returns a new nested list preserving the row structure and order. The function must not mutate the input. | [
"For each row in the input, create a new list by iterating over its values.",
"Keep only values that are >= 0 and add 5 to each.",
"Collect these transformed rows into a new outer list.",
"Return the new nested list."
] | def transform_rows_2_5_0(rows):
return [[value + 5 for value in row if value >= 0] 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 the 'category' values from those records where the sum of the integers in 'values' exceeds 51, preserving the original order. The function must not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record in the input list.",
"If the sum of the record's 'values' list is greater than 51, append the record's 'category' to the result.",
"Return the result list."
] | def categorys_over_total_51(records):
return [row["category"] for row in records if sum(row["values"]) > 51] |
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), keeps only those totals that are >= 1, and returns a new dictionary with the results. The function must not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its counts from both dictionaries (using .get with default 0).",
"If the total is >= 1, add it to a new dictionary.",
"Return the new dictionary."
] | def combine_category_counts_min_1(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 1:
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 complete string to uppercase, keeps only those normalized strings whose length is at least 1, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input... | [
"Initialize an empty dictionary for counts.",
"Loop over each topic in the input list: strip whitespace and convert to uppercase.",
"If the cleaned string has length >= 1, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_topics_upper_1(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().upper()
if len(cleaned) >= 1:
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', keeps only those records where 'quality' <= 20, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values in that sorted order. The function must not mutate the input list. | [
"Filter the list to keep records with quality <= 20.",
"Sort the filtered list by quality in ascending order.",
"Extract the 'title' values from the sorted records.",
"Return the list of titles."
] | def select_titles_by_quality_20_ascending(records):
kept = [row for row in records if row["quality"] <= 20]
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 'units', keeps only those entries where 'units' >= 0, sums the retained 'units' grouped by 'topic', and returns a new dictionary mapping each topic to its total. The function must not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if units >= 0, add units to the total for its topic.",
"Return the totals dictionary."
] | def total_units_by_topic_min_0(records):
totals = {}
for row in records:
if row["units"] >= 0:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'units', computes the average units per topic, keeps only those averages that are at least 10, and returns a dictionary mapping each such topic to its average. The function must not mutate the input list. | [
"Initialize two dictionaries: one for total units per topic, one for count per topic.",
"Loop over each record: add units to the total and increment the count for its topic.",
"Compute the average for each topic as total / count.",
"Return a dictionary of topics whose average >= 10."
] | def qualifying_units_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.