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 label strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 2, returns a dictionary mapping each such 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 uppercase.", "If the cleaned string has length >= 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_upper_2(labels): counts = {} for label in labels: cleaned = label.strip().upper() if len(cleaned) >= 2: 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 'rating' <= 21, 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.
[ "Create a new list containing only records where rating <= 21.", "Sort that list in ascending order by the 'rating' key.", "Extract the 'name' value from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_rating_21_ascending(records): kept = [row for row in records if row["rating"] <= 21] 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 with 'label' and 'cost', keeps only entries where 'cost' >= 0, sums the retained costs grouped by 'label', returns a new dictionary mapping each label to its total cost, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 0, add its cost to the total for its label.", "Return the totals dictionary." ]
def total_cost_by_label_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["label"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'cost', computes the average cost per label, keeps only those averages that are at least 10, returns a new dictionary mapping each such label to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total cost per label, one for count per label.", "Iterate over each record, accumulating totals and counts for each label.", "Compute the average for each label as total / count.", "Return a dictionary containing only those labels where the average >= 10." ]
def qualifying_cost_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 25, counts how many pairs have the first value more than 25 greater than the second, how many have the second more than 25 greater than the first, and how many are within the margin (difference <= 25), returns a ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_25(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 retains only integers greater than 0, returns a new nested list preserving the original row order, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list, create a new list containing only values > 0.", "Append that new list to the result.", "Return the result." ]
def transform_rows_1_10_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 'label' and a list of integer 'values', returns a list of 'label' values for those records where the sum of 'values' exceeds 53, preserving original order, and does not mutate the input list.
[ "Initialize an empty list for result labels.", "Iterate over each record; if sum of its 'values' > 53, append its 'label' to the result.", "Return the result list." ]
def labels_over_total_53(records): return [row["label"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries mapping labels to counts, sums the counts over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 3, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create an empty result dictionary.", "Get the set of all keys from both dictionaries.", "For each key, compute the sum of counts from both (defaulting to 0).", "If the sum >= 3, add it to the result dictionary, then return the result." ]
def combine_label_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of status strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 2, returns a dictionary mapping each such 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 uppercase.", "If the cleaned string has length >= 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_upper_2(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() if len(cleaned) >= 2: 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 'rating' <= 21, 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.
[ "Create a new list containing only records where rating <= 21.", "Sort that list in ascending order by the 'rating' key.", "Extract the 'identifier' value from each sorted record into a new list.", "Return the list of identifiers." ]
def select_identifiers_by_rating_21_ascending(records): kept = [row for row in records if row["rating"] <= 21] 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 with 'status' and 'cost', keeps only entries where 'cost' >= 0, sums the retained costs grouped by 'status', returns a new dictionary mapping each status to its total cost, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 0, add its cost to the total for its status.", "Return the totals dictionary." ]
def total_cost_by_status_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["status"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'status' and 'cost', computes the average cost per status, keeps only those averages that are at least 10, returns a new dictionary mapping each such status to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total cost per status, one for count per status.", "Iterate over each record, accumulating totals and counts for each status.", "Compute the average for each status as total / count.", "Return a dictionary containing only those statuses where the average >= 10." ]
def qualifying_cost_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 26, counts how many pairs have the first value more than 26 greater than the second, how many have the second more than 26 greater than the first, and how many are within the margin (difference <= 26), returns a ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_26(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 retains only integers >= 0 and adds 10 to each retained integer, returns a new nested list preserving the original row order, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list, create a new list containing value + 10 for each value >= 0.", "Append that new list to the result.", "Return the result." ]
def transform_rows_2_10_0(rows): return [[value + 10 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 'status' and a list of integer 'values', returns a list of 'status' values for those records where the sum of 'values' exceeds 53, preserving original order, and does not mutate the input list.
[ "Initialize an empty list for result statuses.", "Iterate over each record; if sum of its 'values' > 53, append its 'status' to the result.", "Return the result list." ]
def statuss_over_total_53(records): return [row["status"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries mapping statuses to counts, sums the counts over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 3, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create an empty result dictionary.", "Get the set of all keys from both dictionaries.", "For each key, compute the sum of counts from both (defaulting to 0).", "If the sum >= 3, add it to the result dictionary, then return the result." ]
def combine_status_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 2, returns a dictionary mapping each such 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 uppercase.", "If the cleaned string has length >= 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_upper_2(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() if len(cleaned) >= 2: 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 'rating' <= 21, 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.
[ "Create a new list containing only records where rating <= 21.", "Sort that list in ascending order by the 'rating' key.", "Extract the 'label' value from each sorted record into a new list.", "Return the list of labels." ]
def select_labels_by_rating_21_ascending(records): kept = [row for row in records if row["rating"] <= 21] kept = sorted(kept, key=lambda row: row["rating"], reverse=False) return [row["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'cost', keeps only entries where 'cost' >= 0, sums the retained costs grouped by 'category', returns a new dictionary mapping each category to its total cost, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 0, add its cost to the total for its category.", "Return the totals dictionary." ]
def total_cost_by_category_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["category"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'cost', computes the average cost per category, keeps only those averages that are at least 10, returns a new dictionary mapping each such category to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total cost per category, one for count per category.", "Iterate over each record, accumulating totals and counts for each category.", "Compute the average for each category as total / count.", "Return a dictionary containing only those categories where the average >= 10."...
def qualifying_cost_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / count...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 27, counts how many pairs have the first value more than 27 greater than the second, how many have the second more than 27 greater than the first, and how many are within the margin (difference <= 27), returns a ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_27(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 retains only integers >= 0 and multiplies each retained integer by 11, returns a new nested list preserving the original row order, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list, create a new list containing value * 11 for each value >= 0.", "Append that new list to the result.", "Return the result." ]
def transform_rows_0_11_0(rows): return [[value * 11 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 'category' and a list of integer 'values', returns a list of 'category' values for those records where the sum of 'values' exceeds 53, preserving original order, and does not mutate the input list.
[ "Initialize an empty list for result categories.", "Iterate over each record; if sum of its 'values' > 53, append its 'category' to the result.", "Return the result list." ]
def categorys_over_total_53(records): return [row["category"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries mapping categories to counts, sums the counts over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 3, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create an empty result dictionary.", "Get the set of all keys from both dictionaries.", "For each key, compute the sum of counts from both (defaulting to 0).", "If the sum >= 3, add it to the result dictionary, then return the result." ]
def combine_category_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 2, returns a dictionary mapping each such 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 uppercase.", "If the cleaned string has length >= 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_2(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() if len(cleaned) >= 2: 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 'score' <= 21, 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.
[ "Create a new list containing only records where score <= 21.", "Sort that list in ascending order by the 'score' key.", "Extract the 'title' value from each sorted record into a new list.", "Return the list of titles." ]
def select_titles_by_score_21_ascending(records): kept = [row for row in records if row["score"] <= 21] kept = sorted(kept, key=lambda row: row["score"], reverse=False) return [row["title"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and 'cost', keeps only entries where 'cost' >= 0, sums the retained costs grouped by 'topic', returns a new dictionary mapping each topic to its total cost, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 0, add its cost to the total for its topic.", "Return the totals dictionary." ]
def total_cost_by_topic_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["topic"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and 'cost', computes the average cost per topic, keeps only those averages that are at least 10, returns a new dictionary mapping each such topic to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total cost per topic, one for count per topic.", "Iterate over each record, accumulating totals and counts for each topic.", "Compute the average for each topic as total / count.", "Return a dictionary containing only those topics where the average >= 10." ]
def qualifying_cost_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair using a margin of 28, counts how many pairs have the first value more than 28 greater than the second, how many have the second more than 28 greater than the first, and how many are within the margin (difference <= 28), returns a ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_28(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 retains only integers greater than 0, returns a new nested list preserving the original row order, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list, create a new list containing only values > 0.", "Append that new list to the result.", "Return the result." ]
def transform_rows_1_11_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 'topic' and a list of integer 'values', returns a list of 'topic' values for those records where the sum of 'values' exceeds 53, preserving original order, and does not mutate the input list.
[ "Initialize an empty list for result topics.", "Iterate over each record; if sum of its 'values' > 53, append its 'topic' to the result.", "Return the result list." ]
def topics_over_total_53(records): return [row["topic"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries mapping topics to counts, sums the counts over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 3, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create an empty result dictionary.", "Get the set of all keys from both dictionaries.", "For each key, compute the sum of counts from both (defaulting to 0).", "If the sum >= 3, add it to the result dictionary, then return the result." ]
def combine_topic_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 2, returns a dictionary mapping each such 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 uppercase.", "If the cleaned string has length >= 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_upper_2(regions): counts = {} for region in regions: cleaned = region.strip().upper() if len(cleaned) >= 2: 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 'score' <= 21, 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.
[ "Create a new list containing only records where score <= 21.", "Sort that list in ascending order by the 'score' key.", "Extract the 'name' value from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_score_21_ascending(records): kept = [row for row in records if row["score"] <= 21] kept = sorted(kept, key=lambda row: row["score"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'region' and 'cost', keeps only entries where 'cost' >= 0, sums the retained costs grouped by 'region', returns a new dictionary mapping each region to its total cost, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 0, add its cost to the total for its region.", "Return the totals dictionary." ]
def total_cost_by_region_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["region"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'region' and 'cost', computes the average cost per region, keeps only those averages that are at least 10, returns a new dictionary mapping each such region to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total cost per region, one for count per region.", "Iterate over each record, accumulating totals and counts for each region.", "Compute the average for each region as total / count.", "Return a dictionary containing only those regions where the average >= 10." ]
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 using a margin of 29, counts how many pairs have the first value more than 29 greater than the second, how many have the second more than 29 greater than the first, and how many are within the margin (difference <= 29), returns a ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_29(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 retains only integers >= 0 and adds 11 to each retained integer, returns a new nested list preserving the original row order, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list, create a new list containing value + 11 for each value >= 0.", "Append that new list to the result.", "Return the result." ]
def transform_rows_2_11_0(rows): return [[value + 11 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 'region' and a list of integer 'values', returns a list of 'region' values for those records where the sum of 'values' exceeds 53, preserving original order, and does not mutate the input list.
[ "Initialize an empty list for result regions.", "Iterate over each record; if sum of its 'values' > 53, append its 'region' to the result.", "Return the result list." ]
def regions_over_total_53(records): return [row["region"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries mapping regions to counts, sums the counts over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 3, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create an empty result dictionary.", "Get the set of all keys from both dictionaries.", "For each key, compute the sum of counts from both (defaulting to 0).", "If the sum >= 3, add it to the result dictionary, then return the result." ]
def combine_region_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of team strings, strips and uppercases each string, keeps only those with length at least 2, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each team string: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_upper_2(teams): counts = {} for team in teams: cleaned = team.strip().upper() if len(cleaned) >= 2: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'score' <= 21, sorts them by 'score' in ascending order, returns a list of the 'identifier' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'score' is <= 21.", "Sort that list by 'score' in ascending order.", "Extract the 'identifier' from each sorted record into a new list.", "Return the list of identifiers." ]
def select_identifiers_by_score_21_ascending(records): kept = [row for row in records if row["score"] <= 21] 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 'team' and 'cost', keeps entries where 'cost' is >= 0, sums the retained costs per team, returns a dictionary mapping team to total cost, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'cost' >= 0, add its 'cost' to the total for its 'team'.", "Return the totals dictionary." ]
def total_cost_by_team_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["team"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'cost', computes the average cost per team, keeps only those averages >= 10, returns a dictionary mapping team to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total cost per team, one for count per team.", "Loop over each record: update totals and counts for its 'team'.", "Compute average for each team as total / count.", "Return a dictionary of teams whose average is >= 10." ]
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 using a margin of 30, counts how many pairs have first ahead by more than 30, second ahead by more than 30, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 30, increment 'first_ahead'; else if right - left > 30, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_30(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, keeps only integers >= 0 in each row, multiplies each retained integer by 12, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value >= 0, append value * 12 to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_0_12_0(rows): return [[value * 12 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 'team' and a list of integer 'values', returns a list of 'team' values whose sum of 'values' exceeds 53, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 53, append the 'team' to the result list.", "Return the result list." ]
def teams_over_total_53(records): return [row["team"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries of team counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 3, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 3, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_team_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips and uppercases each string, keeps only those with length at least 2, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each group string: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 2, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_groups_upper_2(groups): counts = {} for group in groups: cleaned = group.strip().upper() if len(cleaned) >= 2: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'score' <= 21, sorts them by 'score' in ascending order, returns a list of the 'label' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'score' is <= 21.", "Sort that list by 'score' in ascending order.", "Extract the 'label' from each sorted record into a new list.", "Return the list of labels." ]
def select_labels_by_score_21_ascending(records): kept = [row for row in records if row["score"] <= 21] 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 'group' and 'cost', keeps entries where 'cost' is >= 0, sums the retained costs per group, returns a dictionary mapping group to total cost, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'cost' >= 0, add its 'cost' to the total for its 'group'.", "Return the totals dictionary." ]
def total_cost_by_group_min_0(records): totals = {} for row in records: if row["cost"] >= 0: group = row["group"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'cost', computes the average cost per group, keeps only those averages >= 10, returns a dictionary mapping group to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total cost per group, one for count per group.", "Loop over each record: update totals and counts for its 'group'.", "Compute average for each group as total / count.", "Return a dictionary of groups whose average is >= 10." ]
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 using a margin of 31, counts how many pairs have first ahead by more than 31, second ahead by more than 31, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 31, increment 'first_ahead'; else if right - left > 31, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_31(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, keeps only integers greater than 0 in each row, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value > 0, append it to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_1_12_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 'group' and a list of integer 'values', returns a list of 'group' values whose sum of 'values' exceeds 53, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 53, append the 'group' to the result list.", "Return the result list." ]
def groups_over_total_53(records): return [row["group"] for row in records if sum(row["values"]) > 53]
task_code
Write a Python function that takes two dictionaries of group counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 3, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 3, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_group_counts_min_3(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 3: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips and lowercases each string, keeps only those with length at least 3, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each tag string: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_lower_3(tags): counts = {} for tag in tags: cleaned = tag.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'priority' <= 21, sorts them by 'priority' in ascending order, returns a list of the 'title' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'priority' is <= 21.", "Sort that list by 'priority' in ascending order.", "Extract the 'title' from each sorted record into a new list.", "Return the list of titles." ]
def select_titles_by_priority_21_ascending(records): kept = [row for row in records if row["priority"] <= 21] 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 'tag' and 'sales', keeps entries where 'sales' is >= 0, sums the retained sales per tag, returns a dictionary mapping tag to total sales, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'sales' >= 0, add its 'sales' to the total for its 'tag'.", "Return the totals dictionary." ]
def total_sales_by_tag_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["tag"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'sales', computes the average sales per tag, keeps only those averages >= 10, returns a dictionary mapping tag to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total sales per tag, one for count per tag.", "Loop over each record: update totals and counts for its 'tag'.", "Compute average for each tag as total / count.", "Return a dictionary of tags whose average is >= 10." ]
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 using a margin of 32, counts how many pairs have first ahead by more than 32, second ahead by more than 32, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 32, increment 'first_ahead'; else if right - left > 32, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_32(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, keeps only integers >= 0 in each row, adds 12 to each retained integer, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value >= 0, append value + 12 to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_2_12_0(rows): return [[value + 12 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 'tag' and a list of integer 'values', returns a list of 'tag' values whose sum of 'values' exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'tag' to the result list.", "Return the result list." ]
def tags_over_total_54(records): return [row["tag"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries of tag counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 4, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_tag_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of label strings, strips and lowercases each string, keeps only those with length at least 3, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each label string: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_lower_3(labels): counts = {} for label in labels: cleaned = label.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'priority' <= 21, sorts them by 'priority' in ascending order, returns a list of the 'name' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'priority' is <= 21.", "Sort that list by 'priority' in ascending order.", "Extract the 'name' from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_priority_21_ascending(records): kept = [row for row in records if row["priority"] <= 21] 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 'label' and 'sales', keeps entries where 'sales' is >= 0, sums the retained sales per label, returns a dictionary mapping label to total sales, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'sales' >= 0, add its 'sales' to the total for its 'label'.", "Return the totals dictionary." ]
def total_sales_by_label_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["label"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'sales', computes the average sales per label, keeps only those averages >= 10, returns a dictionary mapping label to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total sales per label, one for count per label.", "Loop over each record: update totals and counts for its 'label'.", "Compute average for each label as total / count.", "Return a dictionary of labels whose average is >= 10." ]
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 using a margin of 33, counts how many pairs have first ahead by more than 33, second ahead by more than 33, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 33, increment 'first_ahead'; else if right - left > 33, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_33(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, keeps only integers >= 0 in each row, multiplies each retained integer by 13, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value >= 0, append value * 13 to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_0_13_0(rows): return [[value * 13 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 'label' and a list of integer 'values', returns a list of 'label' values whose sum of 'values' exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'label' to the result list.", "Return the result list." ]
def labels_over_total_54(records): return [row["label"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries of label counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 4, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_label_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of status strings, strips and lowercases each string, keeps only those with length at least 3, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each status string: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_lower_3(statuss): counts = {} for status in statuss: cleaned = status.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'priority' <= 21, sorts them by 'priority' in ascending order, returns a list of the 'identifier' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'priority' is <= 21.", "Sort that list by 'priority' in ascending order.", "Extract the 'identifier' from each sorted record into a new list.", "Return the list of identifiers." ]
def select_identifiers_by_priority_21_ascending(records): kept = [row for row in records if row["priority"] <= 21] 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 'status' and 'sales', keeps entries where 'sales' is >= 0, sums the retained sales per status, returns a dictionary mapping status to total sales, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'sales' >= 0, add its 'sales' to the total for its 'status'.", "Return the totals dictionary." ]
def total_sales_by_status_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["status"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'status' and 'sales', computes the average sales per status, keeps only those averages >= 10, returns a dictionary mapping status to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total sales per status, one for count per status.", "Loop over each record: update totals and counts for its 'status'.", "Compute average for each status as total / count.", "Return a dictionary of statuses whose average is >= 10." ]
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 using a margin of 34, counts how many pairs have first ahead by more than 34, second ahead by more than 34, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 34, increment 'first_ahead'; else if right - left > 34, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_34(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, keeps only integers greater than 0 in each row, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value > 0, append it to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_1_13_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 'status' and a list of integer 'values', returns a list of 'status' values whose sum of 'values' exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'status' to the result list.", "Return the result list." ]
def statuss_over_total_54(records): return [row["status"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries of status counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 4, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_status_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of category strings, strips and lowercases each string, keeps only those with length at least 3, returns a dictionary counting occurrences of each normalized string, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Loop over each category string: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_lower_3(categorys): counts = {} for category in categorys: cleaned = category.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep those with 'priority' <= 21, sorts them by 'priority' in ascending order, returns a list of the 'label' values in that sorted order, and does not mutate the input.
[ "Create a list of records where the 'priority' is <= 21.", "Sort that list by 'priority' in ascending order.", "Extract the 'label' from each sorted record into a new list.", "Return the list of labels." ]
def select_labels_by_priority_21_ascending(records): kept = [row for row in records if row["priority"] <= 21] 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 'category' and 'sales', keeps entries where 'sales' is >= 0, sums the retained sales per category, returns a dictionary mapping category to total sales, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Loop over each record: if 'sales' >= 0, add its 'sales' to the total for its 'category'.", "Return the totals dictionary." ]
def total_sales_by_category_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["category"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'sales', computes the average sales per category, keeps only those averages >= 10, returns a dictionary mapping category to its average, and does not mutate the input.
[ "Initialize two dictionaries: one for total sales per category, one for count per category.", "Loop over each record: update totals and counts for its 'category'.", "Compute average for each category as total / count.", "Return a dictionary of categories whose average is >= 10." ]
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 using a margin of 35, counts how many pairs have first ahead by more than 35, second ahead by more than 35, or within the margin, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate the i...
[ "Initialize a dictionary with three counters set to 0.", "Loop over pairs from both lists using zip.", "If left - right > 35, increment 'first_ahead'; else if right - left > 35, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_35(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, keeps only integers >= 0 in each row, adds 13 to each retained integer, returns a new nested list preserving row order and structure, and does not mutate the input.
[ "For each row in the input, create a new list.", "For each value in the row, if value >= 0, append value + 13 to the new list.", "Collect all new rows into a new nested list.", "Return the new nested list." ]
def transform_rows_2_13_0(rows): return [[value + 13 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 'category' and a list of integer 'values', returns a list of 'category' values whose sum of 'values' exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Loop over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'category' to the result list.", "Return the result list." ]
def categorys_over_total_54(records): return [row["category"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries of category counts, sums values over the union of keys (treating missing keys as 0), keeps only totals >= 4, returns a new dictionary, and does not mutate the inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to a new dictionary.", "Return the new dictionary." ]
def combine_category_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to i...
[ "Initialize an empty dictionary for counts.", "Iterate over each topic string: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_lower_3(topics): counts = {} for topic in topics: cleaned = topic.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' value is <= 21, sorts the kept records by 'quality' 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 quality <= 21.", "Sort the filtered list by quality in ascending order.", "Extract the 'title' values from the sorted list.", "Return the list of titles." ]
def select_titles_by_quality_21_ascending(records): kept = [row for row in records if row["quality"] <= 21] 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 'topic' and 'sales' keys, keeps only entries where sales is >= 0, sums the sales values grouped by topic, returns a new dictionary mapping each topic to its total sales, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if sales >= 0, add sales to the total for its topic.", "Return the totals dictionary." ]
def total_sales_by_topic_min_0(records): totals = {} for row in records: if row["sales"] >= 0: 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 'topic' and 'sales' keys, computes the average sales per topic, keeps only those averages that are at least 10, returns a dictionary mapping each such topic to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total sales per topic, one for count per topic.", "Iterate over each record, updating totals and counts for its topic.", "Compute average for each topic as total / count.", "Return a dictionary of topics whose average >= 10." ]
def qualifying_sales_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["sales"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 36, counts how many pairs have the first value more than 36 ahead of the second, how many have the second more than 36 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_36(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 36: counts["first_ahead"] += 1 elif right - left > 36: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are >= 0, multiplies each retained integer by 14, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values that are >= 0, each multiplied by 14.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_14_0(rows): return [[value * 14 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 'topic' and a list of integer 'values', returns a list of 'topic' values for which the sum of its 'values' list exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'topic' to the result.", "Return the result list." ]
def topics_over_total_54(records): return [row["topic"] for row in records if sum(row["values"]) > 54]
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 (using 0 for missing keys), keeps only those sums that are >= 4, returns a new dictionary with those key-sum pairs, and does 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 >= 4, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_topic_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to ...
[ "Initialize an empty dictionary for counts.", "Iterate over each region string: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_lower_3(regions): counts = {} for region in regions: cleaned = region.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' value is <= 21, sorts the kept records by 'quality' 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 quality <= 21.", "Sort the filtered list by quality in ascending order.", "Extract the 'name' values from the sorted list.", "Return the list of names." ]
def select_names_by_quality_21_ascending(records): kept = [row for row in records if row["quality"] <= 21] 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 'region' and 'sales' keys, keeps only entries where sales is >= 0, sums the sales values grouped by region, returns a new dictionary mapping each region to its total sales, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if sales >= 0, add sales to the total for its region.", "Return the totals dictionary." ]
def total_sales_by_region_min_0(records): totals = {} for row in records: if row["sales"] >= 0: 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 'region' and 'sales' keys, computes the average sales per region, keeps only those averages that are at least 10, returns a dictionary mapping each such region to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total sales per region, one for count per region.", "Iterate over each record, updating totals and counts for its region.", "Compute average for each region as total / count.", "Return a dictionary of regions whose average >= 10." ]
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[...