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 region strings, strips leading/trailing whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 8 appears, returning a dictionary of those counts. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region, strip whitespace and convert to uppercase.",
"If the cleaned string length is at least 8, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_upper_8(regions):
counts = {}
for region in regions:
cleaned = region.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, filters to keep only those with a 'score' key <= 25, sorts the kept records by 'score' in ascending order, and returns a list of the 'name' values from the sorted records. The input list must not be mutated. | [
"Filter the list to keep records where score <= 25.",
"Sort the filtered list by score in ascending order.",
"Extract the 'name' value from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_score_25_ascending(records):
kept = [row for row in records if row["score"] <= 25]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'cost' keys, keeps only entries where cost >= 2, and sums the costs for each region, returning a dictionary mapping each region to its total cost. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if cost >= 2, add the cost to the total for its region.",
"Return the totals dictionary."
] | def total_cost_by_region_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
group = row["region"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'cost' keys, computes the average cost per region, and returns a dictionary mapping each region to its average only if that average is at least 12. The input list must not be mutated. | [
"Initialize two dictionaries: one for total cost per region, one for count per region.",
"Iterate over each record, updating totals and counts for its region.",
"Compute the average for each region as total/count.",
"Return a dictionary of regions whose average is >= 12."
] | def qualifying_cost_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length lists of integers, compares each pair of values (one from each list at the same position) using a margin of 24, and returns a dictionary with counts for 'first_ahead' (first > second by more than 24), 'second_ahead' (second > first by more than 24), and 'within_margin... | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_24_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 24:
counts["first_ahead"] += 1
elif right - left > 24:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, and for each inner list, keeps only integers >= 2 and adds 5 to each kept integer, preserving the order and structure, returning a new nested list. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list that filters values >= 2 and adds 5 to each.",
"Append the transformed inner list to the result.",
"Return the result."
] | def transform_rows_2_5_2(rows):
return [[value + 5 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'values' (a list of integers) keys, and returns a list of 'region' values for which the sum of the integers in 'values' exceeds 65, preserving the original order. The input list must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record; if the sum of its 'values' list is > 65, append the 'region' to the result.",
"Return the result list."
] | def regions_over_total_65(records):
return [row["region"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 15. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of its values from both dictionaries (defaulting to 0).",
"If the total is >= 15, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_region_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of team strings, strips leading/trailing whitespace and converts each string to uppercase, keeps only those normalized strings whose length is at least 8, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each team string, strip and convert to uppercase.",
"If the cleaned string length >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_teams_upper_8(teams):
counts = {}
for team in teams:
cleaned = team.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'score' key is <= 25, sorts the kept records by 'score' 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 score <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["score"] <= 25]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'cost' keys, keeps only entries where cost >= 2, sums the retained costs grouped by team, returns a dictionary mapping each team to its total cost, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if cost >= 2, add its cost to the team's running total.",
"Return the totals dictionary."
] | def total_cost_by_team_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
group = row["team"]
totals[group] = totals.get(group, 0) + row["cost"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'cost' keys, computes the average cost per team, keeps only those averages that are at least 12, returns a dictionary mapping team to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total cost per team, one for count per team.",
"Loop over each record, updating totals and counts for its team.",
"Compute the average for each team as total/count.",
"Return a dictionary of teams whose average >= 12."
] | def qualifying_cost_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 25, how many have second ahead by more than 25, and how many are within that margin (difference <= 25), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 25, increment first_ahead; else if second - first > 25, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_25_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 25:
counts["first_ahead"] += 1
elif right - left > 25:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2, multiplies each kept integer by 6, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values >= 2 multiplied by 6.",
"Append the new list to result.",
"Return result."
] | def transform_rows_0_6_2(rows):
return [[value * 6 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'team' key and a 'values' key (a list of integers), returns a list of team values whose sum of values exceeds 65, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 65, append the 'team' value to result.",
"Return result."
] | def teams_over_total_65(records):
return [row["team"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping team names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 15, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 15, store in result.",
"Return result."
] | def combine_team_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of group strings, strips leading/trailing whitespace and converts each string to uppercase, keeps only those normalized strings whose length is at least 8, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each group string, strip and convert to uppercase.",
"If the cleaned string length >= 8, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_groups_upper_8(groups):
counts = {}
for group in groups:
cleaned = group.strip().upper()
if len(cleaned) >= 8:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'score' key is <= 25, sorts the kept records by 'score' 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 score <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["score"] <= 25]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'group' and 'cost' keys, keeps only entries where cost >= 2, sums the retained costs grouped by group, returns a dictionary mapping each group to its total cost, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if cost >= 2, add its cost to the group's running total.",
"Return the totals dictionary."
] | def total_cost_by_group_min_2(records):
totals = {}
for row in records:
if row["cost"] >= 2:
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 containing 'group' and 'cost' keys, computes the average cost per group, keeps only those averages that are at least 12, returns a dictionary mapping group to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total cost per group, one for count per group.",
"Loop over each record, updating totals and counts for its group.",
"Compute the average for each group as total/count.",
"Return a dictionary of groups whose average >= 12."
] | def qualifying_cost_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["cost"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 26, how many have second ahead by more than 26, and how many are within that margin (difference <= 26), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 26, increment first_ahead; else if second - first > 26, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_26_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 26:
counts["first_ahead"] += 1
elif right - left > 26:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers greater than 2, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values > 2.",
"Append the new list to result.",
"Return result."
] | def transform_rows_1_6_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'group' key and a 'values' key (a list of integers), returns a list of group values whose sum of values exceeds 65, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 65, append the 'group' value to result.",
"Return result."
] | def groups_over_total_65(records):
return [row["group"] for row in records if sum(row["values"]) > 65] |
task_code | Write a Python function that takes two dictionaries mapping group names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 15, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 15, store in result.",
"Return result."
] | def combine_group_counts_min_15(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 15:
result[key] = total
return result |
task_code | Write a Python function that takes a list of tag strings, strips leading/trailing whitespace and converts each string to lowercase, keeps only those normalized strings whose length is at least 9, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each tag string, strip and convert to lowercase.",
"If the cleaned string length >= 9, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_tags_lower_9(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().lower()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 25, sorts the kept records by 'priority' 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 priority <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["priority"] <= 25]
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 containing 'tag' and 'sales' keys, keeps only entries where sales >= 2, sums the retained sales grouped by tag, returns a dictionary mapping each tag to its total sales, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if sales >= 2, add its sales to the tag's running total.",
"Return the totals dictionary."
] | def total_sales_by_tag_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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 containing 'tag' and 'sales' keys, computes the average sales per tag, keeps only those averages that are at least 12, returns a dictionary mapping tag to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total sales per tag, one for count per tag.",
"Loop over each record, updating totals and counts for its tag.",
"Compute the average for each tag as total/count.",
"Return a dictionary of tags whose average >= 12."
] | def qualifying_sales_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 27, how many have second ahead by more than 27, and how many are within that margin (difference <= 27), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 27, increment first_ahead; else if second - first > 27, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_27_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 27:
counts["first_ahead"] += 1
elif right - left > 27:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2, adds 6 to each kept integer, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values >= 2 plus 6.",
"Append the new list to result.",
"Return result."
] | def transform_rows_2_6_2(rows):
return [[value + 6 for value in row if value >= 2] 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 (a list of integers), returns a list of tag values whose sum of values exceeds 66, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 66, append the 'tag' value to result.",
"Return result."
] | def tags_over_total_66(records):
return [row["tag"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping tag names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 16, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 16, store in result.",
"Return result."
] | def combine_tag_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
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 string to lowercase, keeps only those normalized strings whose length is at least 9, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each label string, strip and convert to lowercase.",
"If the cleaned string length >= 9, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_labels_lower_9(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 25, sorts the kept records by 'priority' 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 priority <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["priority"] <= 25]
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 containing 'label' and 'sales' keys, keeps only entries where sales >= 2, sums the retained sales grouped by label, returns a dictionary mapping each label to its total sales, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if sales >= 2, add its sales to the label's running total.",
"Return the totals dictionary."
] | def total_sales_by_label_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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 containing 'label' and 'sales' keys, computes the average sales per label, keeps only those averages that are at least 12, returns a dictionary mapping label to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total sales per label, one for count per label.",
"Loop over each record, updating totals and counts for its label.",
"Compute the average for each label as total/count.",
"Return a dictionary of labels whose average >= 12."
] | def qualifying_sales_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 28, how many have second ahead by more than 28, and how many are within that margin (difference <= 28), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 28, increment first_ahead; else if second - first > 28, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_28_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 28:
counts["first_ahead"] += 1
elif right - left > 28:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2, multiplies each kept integer by 7, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values >= 2 multiplied by 7.",
"Append the new list to result.",
"Return result."
] | def transform_rows_0_7_2(rows):
return [[value * 7 for value in row if value >= 2] 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 (a list of integers), returns a list of label values whose sum of values exceeds 66, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 66, append the 'label' value to result.",
"Return result."
] | def labels_over_total_66(records):
return [row["label"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping label names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 16, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 16, store in result.",
"Return result."
] | def combine_label_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
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 string to lowercase, keeps only those normalized strings whose length is at least 9, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each status string, strip and convert to lowercase.",
"If the cleaned string length >= 9, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_statuss_lower_9(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 25, sorts the kept records by 'priority' 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 priority <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["priority"] <= 25]
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 containing 'status' and 'sales' keys, keeps only entries where sales >= 2, sums the retained sales grouped by status, returns a dictionary mapping each status to its total sales, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if sales >= 2, add its sales to the status's running total.",
"Return the totals dictionary."
] | def total_sales_by_status_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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 containing 'status' and 'sales' keys, computes the average sales per status, keeps only those averages that are at least 12, returns a dictionary mapping status to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total sales per status, one for count per status.",
"Loop over each record, updating totals and counts for its status.",
"Compute the average for each status as total/count.",
"Return a dictionary of statuses whose average >= 12."
] | def qualifying_sales_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 29, how many have second ahead by more than 29, and how many are within that margin (difference <= 29), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 29, increment first_ahead; else if second - first > 29, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_29_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 29:
counts["first_ahead"] += 1
elif right - left > 29:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers greater than 2, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values > 2.",
"Append the new list to result.",
"Return result."
] | def transform_rows_1_7_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing a 'status' key and a 'values' key (a list of integers), returns a list of status values whose sum of values exceeds 66, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 66, append the 'status' value to result.",
"Return result."
] | def statuss_over_total_66(records):
return [row["status"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping status names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 16, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 16, store in result.",
"Return result."
] | def combine_status_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
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 string to lowercase, keeps only those normalized strings whose length is at least 9, returns a dictionary counting how many times each such normalized string appears, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Loop over each category string, strip and convert to lowercase.",
"If the cleaned string length >= 9, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_categorys_lower_9(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 25, sorts the kept records by 'priority' 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 priority <= 25.",
"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_25_ascending(records):
kept = [row for row in records if row["priority"] <= 25]
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 containing 'category' and 'sales' keys, keeps only entries where sales >= 2, sums the retained sales grouped by category, returns a dictionary mapping each category to its total sales, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record; if sales >= 2, add its sales to the category's running total.",
"Return the totals dictionary."
] | def total_sales_by_category_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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 containing 'category' and 'sales' keys, computes the average sales per category, keeps only those averages that are at least 12, returns a dictionary mapping category to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total sales per category, one for count per category.",
"Loop over each record, updating totals and counts for its category.",
"Compute the average for each category as total/count.",
"Return a dictionary of categories whose average >= 12."
] | def qualifying_sales_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["sales"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / cou... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair of values (first list value minus second list value), counts how many pairs have first ahead by more than 30, how many have second ahead by more than 30, and how many are within that margin (difference <= 30), returns a dictionary wit... | [
"Initialize counts dictionary with three keys set to 0.",
"Loop over pairs using zip; compute difference.",
"If first - second > 30, increment first_ahead; else if second - first > 30, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_30_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 30:
counts["first_ahead"] += 1
elif right - left > 30:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, for each inner list keeps only integers >= 2, adds 7 to each kept integer, returns a new nested list preserving the original row order and structure, and does not mutate the input. | [
"Initialize an empty result list.",
"For each inner list, create a new list with values >= 2 plus 7.",
"Append the new list to result.",
"Return result."
] | def transform_rows_2_7_2(rows):
return [[value + 7 for value in row if value >= 2] 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 (a list of integers), returns a list of category values whose sum of values exceeds 66, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record; compute sum of its 'values' list.",
"If sum > 66, append the 'category' value to result.",
"Return result."
] | def categorys_over_total_66(records):
return [row["category"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping category names to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are >= 16, returns a new dictionary with those key-total pairs, and does not mutate the input dictionaries... | [
"Initialize an empty result dictionary.",
"Get the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 16, store in result.",
"Return result."
] | def combine_category_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
result[key] = total
return result |
task_code | Write a Python function that takes a list of topic strings, strips whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_lower_9(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 9:
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'), filters to keep only those where 'quality' <= 25, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with quality <= 25.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'title' values from the sorted records into a new list.",
"Return the list of titles."
] | def select_titles_by_quality_25_ascending(records):
kept = [row for row in records if row["quality"] <= 25]
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'), keeps only those where 'sales' >= 2, and returns a dictionary mapping each topic to the sum of its retained sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 2, add sales to the total for its topic.",
"Return the totals dictionary."
] | def total_sales_by_topic_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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'), computes the average sales per topic, and returns a dictionary mapping each topic to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per topic and one for count per topic.",
"Iterate over each record, updating totals and counts for its topic.",
"Compute the average for each topic as total / count.",
"Return a dictionary of topics whose average is >= 12."
] | def qualifying_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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 31, 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 l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 31, increment first_ahead; else if right - left > 31, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_31_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 31:
counts["first_ahead"] += 1
elif right - left > 31:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 2 within each inner list, multiplies each retained integer by 8, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values >= 2 and multiplying each by 8.",
"Collect the transformed inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_0_8_2(rows):
return [[value * 8 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'topic' and 'values', where 'values' is a list of integers), and returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 66, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 66, append the 'topic' to the result list.",
"Return the result list."
] | def topics_over_total_66(records):
return [row["topic"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 16. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 16, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_topic_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
result[key] = total
return result |
task_code | Write a Python function that takes a list of region strings, strips whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_lower_9(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 9:
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'), filters to keep only those where 'quality' <= 25, sorts the kept records by 'quality' in ascending order, and returns a list of the 'name' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with quality <= 25.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'name' values from the sorted records into a new list.",
"Return the list of names."
] | def select_names_by_quality_25_ascending(records):
kept = [row for row in records if row["quality"] <= 25]
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'), keeps only those where 'sales' >= 2, and returns a dictionary mapping each region to the sum of its retained sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 2, add sales to the total for its region.",
"Return the totals dictionary."
] | def total_sales_by_region_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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'), computes the average sales per region, and returns a dictionary mapping each region to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per region and one for count per region.",
"Iterate over each record, updating totals and counts for its region.",
"Compute the average for each region as total / count.",
"Return a dictionary of regions whose average is >= 12."
] | 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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 32, 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 l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 32, increment first_ahead; else if right - left > 32, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_32_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 32:
counts["first_ahead"] += 1
elif right - left > 32:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers greater than 2 within each inner list, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values > 2.",
"Collect the filtered inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_1_8_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'region' and 'values', where 'values' is a list of integers), and returns a list of 'region' values for which the sum of the integers in 'values' exceeds 66, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 66, append the 'region' to the result list.",
"Return the result list."
] | def regions_over_total_66(records):
return [row["region"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 16. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 16, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_region_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
result[key] = total
return result |
task_code | Write a Python function that takes a list of team strings, strips whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each team string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_lower_9(teams):
counts = {}
for team in teams:
cleaned = team.strip().lower()
if len(cleaned) >= 9:
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'), filters to keep only those where 'quality' <= 25, sorts the kept records by 'quality' in ascending order, and returns a list of the 'identifier' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with quality <= 25.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_quality_25_ascending(records):
kept = [row for row in records if row["quality"] <= 25]
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'), keeps only those where 'sales' >= 2, and returns a dictionary mapping each team to the sum of its retained sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 2, add sales to the total for its team.",
"Return the totals dictionary."
] | def total_sales_by_team_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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'), computes the average sales per team, and returns a dictionary mapping each team to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per team and one for count per team.",
"Iterate over each record, updating totals and counts for its team.",
"Compute the average for each team as total / count.",
"Return a dictionary of teams whose average is >= 12."
] | 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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 33, 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 l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 33, increment first_ahead; else if right - left > 33, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_33_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 33:
counts["first_ahead"] += 1
elif right - left > 33:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 2 within each inner list, adds 8 to each retained integer, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values >= 2 and adding 8 to each.",
"Collect the transformed inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_2_8_2(rows):
return [[value + 8 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'team' and 'values', where 'values' is a list of integers), and returns a list of 'team' values for which the sum of the integers in 'values' exceeds 66, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 66, append the 'team' to the result list.",
"Return the result list."
] | def teams_over_total_66(records):
return [row["team"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 16. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 16, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_team_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
result[key] = total
return result |
task_code | Write a Python function that takes a list of group strings, strips whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each group string: strip whitespace and convert to lowercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_lower_9(groups):
counts = {}
for group in groups:
cleaned = group.strip().lower()
if len(cleaned) >= 9:
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'), filters to keep only those where 'quality' <= 25, sorts the kept records by 'quality' in ascending order, and returns a list of the 'label' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with quality <= 25.",
"Sort the filtered list by the 'quality' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return the list of labels."
] | def select_labels_by_quality_25_ascending(records):
kept = [row for row in records if row["quality"] <= 25]
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'), keeps only those where 'sales' >= 2, and returns a dictionary mapping each group to the sum of its retained sales. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if sales >= 2, add sales to the total for its group.",
"Return the totals dictionary."
] | def total_sales_by_group_min_2(records):
totals = {}
for row in records:
if row["sales"] >= 2:
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'), computes the average sales per group, and returns a dictionary mapping each group to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total sales per group and one for count per group.",
"Iterate over each record, updating totals and counts for its group.",
"Compute the average for each group as total / count.",
"Return a dictionary of groups whose average is >= 12."
] | 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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 34, 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 l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 34, increment first_ahead; else if right - left > 34, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_34_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 34:
counts["first_ahead"] += 1
elif right - left > 34:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 2 within each inner list, multiplies each retained integer by 9, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values >= 2 and multiplying each by 9.",
"Collect the transformed inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_0_9_2(rows):
return [[value * 9 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'group' and 'values', where 'values' is a list of integers), and returns a list of 'group' values for which the sum of the integers in 'values' exceeds 66, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 66, append the 'group' to the result list.",
"Return the result list."
] | def groups_over_total_66(records):
return [row["group"] for row in records if sum(row["values"]) > 66] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 16. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 16, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_group_counts_min_16(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 16:
result[key] = total
return result |
task_code | Write a Python function that takes a list of tag strings, strips whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_upper_9(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().upper()
if len(cleaned) >= 9:
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'), filters to keep only those where 'rank' <= 25, sorts the kept records by 'rank' in ascending order, and returns a list of the 'title' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 25.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'title' values from the sorted records into a new list.",
"Return the list of titles."
] | def select_titles_by_rank_25_ascending(records):
kept = [row for row in records if row["rank"] <= 25]
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'), keeps only those where 'items' >= 2, and returns a dictionary mapping each tag to the sum of its retained items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if items >= 2, add items to the total for its tag.",
"Return the totals dictionary."
] | def total_items_by_tag_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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'), computes the average items per tag, and returns a dictionary mapping each tag to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per tag and one for count per tag.",
"Iterate over each record, updating totals and counts for its tag.",
"Compute the average for each tag as total / count.",
"Return a dictionary of tags whose average is >= 12."
] | def qualifying_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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 35, 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 l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 35, increment first_ahead; else if right - left > 35, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_35_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 35:
counts["first_ahead"] += 1
elif right - left > 35:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers greater than 2 within each inner list, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values > 2.",
"Collect the filtered inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_1_9_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'tag' and 'values', where 'values' is a list of integers), and returns a list of 'tag' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'tag' to the result list.",
"Return the result list."
] | def tags_over_total_67(records):
return [row["tag"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 17. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_tag_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 9, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_upper_9(labels):
counts = {}
for label in labels:
cleaned = label.strip().upper()
if len(cleaned) >= 9:
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'), filters to keep only those where 'rank' <= 25, sorts the kept records by 'rank' in ascending order, and returns a list of the 'name' values in that sorted order. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 25.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'name' values from the sorted records into a new list.",
"Return the list of names."
] | def select_names_by_rank_25_ascending(records):
kept = [row for row in records if row["rank"] <= 25]
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'), keeps only those where 'items' >= 2, and returns a dictionary mapping each label to the sum of its retained items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if items >= 2, add items to the total for its label.",
"Return the totals dictionary."
] | def total_items_by_label_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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'), computes the average items per label, and returns a dictionary mapping each label to its average only if that average is >= 12. Do not mutate the input list. | [
"Initialize two dictionaries: one for total items per label and one for count per label.",
"Iterate over each record, updating totals and counts for its label.",
"Compute the average for each label as total / count.",
"Return a dictionary of labels whose average is >= 12."
] | def qualifying_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]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.