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 topic strings, strips leading/trailing whitespace and converts each to lowercase, then counts how many times each normalized string appears but only includes those whose length is at least 7. Return a dictionary mapping each qualifying normalized string to its count. Do not ...
[ "Initialize an empty dictionary for counts.", "Iterate over each topic, strip whitespace and convert to lowercase.", "If the cleaned string has length >= 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_lower_7(topics): counts = {} for topic in topics: cleaned = topic.strip().lower() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'score' and 'title', filters to keep only those with score <= 24, sorts the kept records by score 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 where score <= 24.", "Sort the filtered list by the 'score' key in ascending order.", "Extract the 'title' values from the sorted list into a new list.", "Return the list of titles." ]
def select_titles_by_score_24_ascending(records): kept = [row for row in records if row["score"] <= 24] 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 keys 'topic' and 'hours', keeps only entries where hours >= 2, then sums the hours for each distinct topic and returns a dictionary mapping each topic to its total hours. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record, check if hours >= 2.", "If so, add the hours to the total for that topic.", "Return the totals dictionary." ]
def total_hours_by_topic_min_2(records): totals = {} for row in records: if row["hours"] >= 2: group = row["topic"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'hours', computes the average hours per topic across all records, and returns a dictionary mapping each topic to its average only if that average is at least 12. Do not mutate the input list.
[ "Initialize two dictionaries: one for total hours per topic, one for count per topic.", "Iterate over each record, update totals and counts for its topic.", "Compute the average for each topic as total / count.", "Return a dictionary of topics whose average >= 12." ]
def qualifying_hours_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of values using a margin of 100, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over paired elements using zip.", "If left - right > 100, increment first_ahead; else if right - left > 100, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_100(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 100: counts["first_ahead"] += 1 elif right - left > 100: counts["second_ahead"] += 1 else:...
task_code
Write a Python function that takes a nested list of integers, and for each inner list, retains only integers that are greater than 1, preserving the order within each row. Return a new nested list with the filtered rows. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list by filtering values > 1.", "Append the filtered inner list to the result.", "Return the result." ]
def transform_rows_1_16_1(rows): return [[value for value in row if value > 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'values' (where 'values' is a list of integers), and returns a list of the 'topic' values for which the sum of the integers in 'values' exceeds 62, 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 > 62, append the record's 'topic' to the result.", "Return the result list." ]
def topics_over_total_62(records): return [row["topic"] for row in records if sum(row["values"]) > 62]
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 at least 12. 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 >= 12, add the key-value pair to the result dictionary.", "Return the result dictionary." ]
def combine_topic_counts_min_12(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 12: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each to lowercase, then counts how many times each normalized string appears but only includes those whose length is at least 7. Return a dictionary mapping each qualifying normalized string to its count. Do not...
[ "Initialize an empty dictionary for counts.", "Iterate over each region, strip whitespace and convert to lowercase.", "If the cleaned string has length >= 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_lower_7(regions): counts = {} for region in regions: cleaned = region.strip().lower() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'score' and 'name', filters to keep only those with score <= 24, sorts the kept records by score 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 where score <= 24.", "Sort the filtered list by the 'score' key in ascending order.", "Extract the 'name' values from the sorted list into a new list.", "Return the list of names." ]
def select_names_by_score_24_ascending(records): kept = [row for row in records if row["score"] <= 24] 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 keys 'region' and 'hours', keeps only entries where hours >= 2, then sums the hours for each distinct region and returns a dictionary mapping each region to its total hours. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record, check if hours >= 2.", "If so, add the hours to the total for that region.", "Return the totals dictionary." ]
def total_hours_by_region_min_2(records): totals = {} for row in records: if row["hours"] >= 2: group = row["region"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries, each with keys 'region' and 'hours', computes the average hours per region across all records, and returns a dictionary mapping each region to its average only if that average is at least 12. Do not mutate the input list.
[ "Initialize two dictionaries: one for total hours per region, one for count per region.", "Iterate over each record, update totals and counts for its region.", "Compute the average for each region as total / count.", "Return a dictionary of regions whose average >= 12." ]
def qualifying_hours_averages_by_region(records): totals = {} counts = {} for row in records: group = row["region"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of values using a margin of 0, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over paired elements using zip.", "If left - right > 0, increment first_ahead; else if right - left > 0, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_0_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 0: counts["first_ahead"] += 1 elif right - left > 0: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, and for each inner list, retains only integers that are at least 1 and adds 16 to each retained integer, preserving the order within each row. Return a new nested list with the transformed rows. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list by filtering values >= 1 and adding 16 to each.", "Append the transformed inner list to the result.", "Return the result." ]
def transform_rows_2_16_1(rows): return [[value + 16 for value in row if value >= 1] 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 the 'region' values for which the sum of the integers in 'values' exceeds 62, 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 > 62, append the record's 'region' to the result.", "Return the result list." ]
def regions_over_total_62(records): return [row["region"] for row in records if sum(row["values"]) > 62]
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 at least 12. 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 >= 12, add the key-value pair to the result dictionary.", "Return the result dictionary." ]
def combine_region_counts_min_12(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 12: result[key] = total return result
task_code
Write a Python function that takes a list of team strings, strips and lowercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each team string, strip and convert to lowercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_teams_lower_7(teams): counts = {} for team in teams: cleaned = team.strip().lower() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'score' <= 24, sorts them by score in ascending order, returns a list of the 'identifier' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with score <= 24.", "Sort the filtered records by score in ascending order.", "Extract the 'identifier' values from the sorted records.", "Return the list of identifiers." ]
def select_identifiers_by_score_24_ascending(records): kept = [row for row in records if row["score"] <= 24] 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 with 'team' and 'hours' keys, keeps only entries where hours >= 2, sums the hours for each team, returns a dictionary mapping team to total hours, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if hours >= 2, add hours to the team's total.", "Return the totals dictionary." ]
def total_hours_by_team_min_2(records): totals = {} for row in records: if row["hours"] >= 2: group = row["team"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'team' and 'hours' keys, computes the average hours per team, retains only averages >= 12, returns a dictionary mapping team to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total hours per team, one for count per team.", "Iterate over records, accumulating totals and counts.", "Compute average for each team as total / count.", "Return a dictionary of teams whose average is at least 12." ]
def qualifying_hours_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 1, counts pairs where first > second + 1, second > first + 1, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_1_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 1: counts["first_ahead"] += 1 elif right - left > 1: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains integers >= 1, multiplies each retained integer by 17 within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values >= 1 multiplied by 17.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_17_1(rows): return [[value * 17 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'team' and 'values' (list of ints), returns a list of team names whose sum of values > 62, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 62, append 'team' to result.", "Return the result list." ]
def teams_over_total_62(records): return [row["team"] for row in records if sum(row["values"]) > 62]
task_code
Write a Python function that takes two dictionaries of team counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 12, returns a new dictionary, and does not mutate 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 >= 12, add to result dictionary.", "Return the result dictionary." ]
def combine_team_counts_min_12(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 12: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips and lowercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each group string, strip and convert to lowercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_groups_lower_7(groups): counts = {} for group in groups: cleaned = group.strip().lower() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'score' <= 24, sorts them by score in ascending order, returns a list of the 'label' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with score <= 24.", "Sort the filtered records by score in ascending order.", "Extract the 'label' values from the sorted records.", "Return the list of labels." ]
def select_labels_by_score_24_ascending(records): kept = [row for row in records if row["score"] <= 24] 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 with 'group' and 'hours' keys, keeps only entries where hours >= 2, sums the hours for each group, returns a dictionary mapping group to total hours, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if hours >= 2, add hours to the group's total.", "Return the totals dictionary." ]
def total_hours_by_group_min_2(records): totals = {} for row in records: if row["hours"] >= 2: group = row["group"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'group' and 'hours' keys, computes the average hours per group, retains only averages >= 12, returns a dictionary mapping group to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total hours per group, one for count per group.", "Iterate over records, accumulating totals and counts.", "Compute average for each group as total / count.", "Return a dictionary of groups whose average is at least 12." ]
def qualifying_hours_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 2, counts pairs where first > second + 2, second > first + 2, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_2_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 2: counts["first_ahead"] += 1 elif right - left > 2: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers > 1 within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values > 1.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_17_1(rows): return [[value for value in row if value > 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'group' and 'values' (list of ints), returns a list of group names whose sum of values > 62, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 62, append 'group' to result.", "Return the result list." ]
def groups_over_total_62(records): return [row["group"] for row in records if sum(row["values"]) > 62]
task_code
Write a Python function that takes two dictionaries of group counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 12, returns a new dictionary, and does not mutate 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 >= 12, add to result dictionary.", "Return the result dictionary." ]
def combine_group_counts_min_12(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 12: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips and uppercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each tag string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_tags_upper_7(tags): counts = {} for tag in tags: cleaned = tag.strip().upper() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'priority' <= 24, sorts them by priority in ascending order, returns a list of the 'title' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with priority <= 24.", "Sort the filtered records by priority in ascending order.", "Extract the 'title' values from the sorted records.", "Return the list of titles." ]
def select_titles_by_priority_24_ascending(records): kept = [row for row in records if row["priority"] <= 24] 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 with 'tag' and 'units' keys, keeps only entries where units >= 2, sums the units for each tag, returns a dictionary mapping tag to total units, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add units to the tag's total.", "Return the totals dictionary." ]
def total_units_by_tag_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["tag"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'tag' and 'units' keys, computes the average units per tag, retains only averages >= 12, returns a dictionary mapping tag to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total units per tag, one for count per tag.", "Iterate over records, accumulating totals and counts.", "Compute average for each tag as total / count.", "Return a dictionary of tags whose average is at least 12." ]
def qualifying_units_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 3, counts pairs where first > second + 3, second > first + 3, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_3_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 3: counts["first_ahead"] += 1 elif right - left > 3: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains integers >= 1, adds 17 to each retained integer within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values >= 1 with 17 added.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_17_1(rows): return [[value + 17 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'tag' and 'values' (list of ints), returns a list of tag names whose sum of values > 63, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 63, append 'tag' to result.", "Return the result list." ]
def tags_over_total_63(records): return [row["tag"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of tag counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 13, returns a new dictionary, and does not mutate 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 >= 13, add to result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of label strings, strips and uppercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each label string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_labels_upper_7(labels): counts = {} for label in labels: cleaned = label.strip().upper() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'priority' <= 24, sorts them by priority in ascending order, returns a list of the 'name' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with priority <= 24.", "Sort the filtered records by priority in ascending order.", "Extract the 'name' values from the sorted records.", "Return the list of names." ]
def select_names_by_priority_24_ascending(records): kept = [row for row in records if row["priority"] <= 24] 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 with 'label' and 'units' keys, keeps only entries where units >= 2, sums the units for each label, returns a dictionary mapping label to total units, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add units to the label's total.", "Return the totals dictionary." ]
def total_units_by_label_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["label"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'label' and 'units' keys, computes the average units per label, retains only averages >= 12, returns a dictionary mapping label to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total units per label, one for count per label.", "Iterate over records, accumulating totals and counts.", "Compute average for each label as total / count.", "Return a dictionary of labels whose average is at least 12." ]
def qualifying_units_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 4, counts pairs where first > second + 4, second > first + 4, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_4_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 4: counts["first_ahead"] += 1 elif right - left > 4: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains integers >= 1, multiplies each retained integer by 18 within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values >= 1 multiplied by 18.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_18_1(rows): return [[value * 18 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'label' and 'values' (list of ints), returns a list of label names whose sum of values > 63, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 63, append 'label' to result.", "Return the result list." ]
def labels_over_total_63(records): return [row["label"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of label counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 13, returns a new dictionary, and does not mutate 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 >= 13, add to result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of status strings, strips and uppercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each status string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_statuss_upper_7(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'priority' <= 24, sorts them by priority in ascending order, returns a list of the 'identifier' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with priority <= 24.", "Sort the filtered records by priority in ascending order.", "Extract the 'identifier' values from the sorted records.", "Return the list of identifiers." ]
def select_identifiers_by_priority_24_ascending(records): kept = [row for row in records if row["priority"] <= 24] 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 with 'status' and 'units' keys, keeps only entries where units >= 2, sums the units for each status, returns a dictionary mapping status to total units, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add units to the status's total.", "Return the totals dictionary." ]
def total_units_by_status_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["status"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'status' and 'units' keys, computes the average units per status, retains only averages >= 12, returns a dictionary mapping status to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total units per status, one for count per status.", "Iterate over records, accumulating totals and counts.", "Compute average for each status as total / count.", "Return a dictionary of statuses whose average is at least 12." ]
def qualifying_units_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 5, counts pairs where first > second + 5, second > first + 5, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_5_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 5: counts["first_ahead"] += 1 elif right - left > 5: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers > 1 within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values > 1.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_18_1(rows): return [[value for value in row if value > 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'status' and 'values' (list of ints), returns a list of status names whose sum of values > 63, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 63, append 'status' to result.", "Return the result list." ]
def statuss_over_total_63(records): return [row["status"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of status counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 13, returns a new dictionary, and does not mutate 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 >= 13, add to result dictionary.", "Return the result dictionary." ]
def combine_status_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of category strings, strips and uppercases each string, counts only those with length at least 7, returns a dictionary mapping normalized strings to their counts, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each category string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_categorys_upper_7(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() if len(cleaned) >= 7: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters for records where 'priority' <= 24, sorts them by priority in ascending order, returns a list of the 'label' values in that sorted order, and does not mutate the input.
[ "Filter the list to keep only records with priority <= 24.", "Sort the filtered records by priority in ascending order.", "Extract the 'label' values from the sorted records.", "Return the list of labels." ]
def select_labels_by_priority_24_ascending(records): kept = [row for row in records if row["priority"] <= 24] 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 with 'category' and 'units' keys, keeps only entries where units >= 2, sums the units for each category, returns a dictionary mapping category to total units, and does not mutate the input.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add units to the category's total.", "Return the totals dictionary." ]
def total_units_by_category_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["category"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'category' and 'units' keys, computes the average units per category, retains only averages >= 12, returns a dictionary mapping category to average, and does not mutate the input.
[ "Initialize two dictionaries: one for total units per category, one for count per category.", "Iterate over records, accumulating totals and counts.", "Compute average for each category as total / count.", "Return a dictionary of categories whose average is at least 12." ]
def qualifying_units_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / cou...
task_code
Write a Python function that takes two equal-length integer lists, compares paired values with a margin of 6, counts pairs where first > second + 6, second > first + 6, or neither, returns a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin', and does not mutate inputs.
[ "Initialize counts dictionary with three keys set to 0.", "Iterate over pairs using zip.", "For each pair, determine which condition holds and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_6_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 6: counts["first_ahead"] += 1 elif right - left > 6: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains integers >= 1, adds 18 to each retained integer within each row, returns a new nested list preserving row structure and order, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values >= 1 with 18 added.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_18_1(rows): return [[value + 18 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'category' and 'values' (list of ints), returns a list of category names whose sum of values > 63, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over records; if sum of 'values' > 63, append 'category' to result.", "Return the result list." ]
def categorys_over_total_63(records): return [row["category"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of category counts, sums values over the union of keys (missing keys treated as 0), retains only totals >= 13, returns a new dictionary, and does not mutate 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 >= 13, add to result dictionary.", "Return the result dictionary." ]
def combine_category_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears among those with length at least 7, returning a dictionary of those counts. The input list must not be mutated.
[ "Initialize an empty dictionary for counts.", "Iterate over each topic string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_7(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() if len(cleaned) >= 7: 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 less than or equal to 24, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values from the sorted records. The input list must not be mutated.
[ "Filter the list to keep records with quality <= 24.", "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_24_ascending(records): kept = [row for row in records if row["quality"] <= 24] 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 containing 'topic' and 'units', keeps only entries where 'units' is at least 2, sums the retained 'units' grouped by 'topic', and returns a dictionary mapping each topic to its total. The input list must not be mutated.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add its units to the total for its topic.", "Return the totals dictionary." ]
def total_units_by_topic_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["topic"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each containing 'topic' and 'units', computes the average units per topic, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying topic to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total units per topic, one for count per topic.", "Iterate over each record, updating totals and counts for its topic.", "Compute the average for each topic as total divided by count.", "Return a dictionary of topics whose average is >= 12." ]
def qualifying_units_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
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 7, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 7), 'second_ahead' (second minus first > 7), 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 applies and increment the corresponding count.", "Return the dictionary." ]
def compare_pairs_with_margin_7_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 7: counts["first_ahead"] += 1 elif right - left > 7: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 1 within each inner list, multiplies each retained integer by 19, and returns a new nested list preserving the original row order and structure. The input must not be mutated.
[ "For each inner list, filter to keep values >= 1.", "Multiply each kept value by 19.", "Collect the transformed inner lists into a new outer list.", "Return the new nested list." ]
def transform_rows_0_19_1(rows): return [[value * 19 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each containing a 'topic' key and a 'values' key that is a list of integers, returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 63, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 63, append the record's 'topic' to the result list.", "Return the result list." ]
def topics_over_total_63(records): return [row["topic"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of topic counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 13, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated.
[ "Initialize an empty result dictionary.", "Compute the union of keys from both dictionaries.", "For each key, sum the values (using .get with default 0).", "If the total >= 13, add the key and total to the result dictionary; return it." ]
def combine_topic_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears among those with length at least 7, returning a dictionary of those counts. The input list must not be mutated.
[ "Initialize an empty dictionary for counts.", "Iterate over each region string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_upper_7(regions): counts = {} for region in regions: cleaned = region.strip().upper() if len(cleaned) >= 7: 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 less than or equal to 24, sorts the kept records by 'quality' in ascending order, and returns a list of the 'name' values from the sorted records. The input list must not be mutated.
[ "Filter the list to keep records with quality <= 24.", "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_24_ascending(records): kept = [row for row in records if row["quality"] <= 24] 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 containing 'region' and 'units', keeps only entries where 'units' is at least 2, sums the retained 'units' grouped by 'region', and returns a dictionary mapping each region to its total. The input list must not be mutated.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add its units to the total for its region.", "Return the totals dictionary." ]
def total_units_by_region_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["region"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each containing 'region' and 'units', computes the average units per region, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying region to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total units 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 divided by count.", "Return a dictionary of regions whose average is >= 12." ]
def qualifying_units_averages_by_region(records): totals = {} counts = {} for row in records: group = row["region"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 8, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 8), 'second_ahead' (second minus first > 8), and 'within_margin' (otherwise). The input lists must not be mu...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over paired elements using zip; for each pair, determine which category applies and increment the corresponding count.", "Return the dictionary." ]
def compare_pairs_with_margin_8_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 8: counts["first_ahead"] += 1 elif right - left > 8: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers greater than 1 within each inner list, and returns a new nested list preserving the original row order and structure. The input must not be mutated.
[ "For each inner list, filter to keep values > 1.", "Collect the filtered inner lists into a new outer list.", "Return the new nested list." ]
def transform_rows_1_19_1(rows): return [[value for value in row if value > 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each containing a 'region' key and a 'values' key that is a list of integers, returns a list of 'region' values for which the sum of the integers in 'values' exceeds 63, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 63, append the record's 'region' to the result list.", "Return the result list." ]
def regions_over_total_63(records): return [row["region"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of region counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 13, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated.
[ "Initialize an empty result dictionary.", "Compute the union of keys from both dictionaries.", "For each key, sum the values (using .get with default 0).", "If the total >= 13, add the key and total to the result dictionary; return it." ]
def combine_region_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of team strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears among those with length at least 7, returning a dictionary of those counts. The input list must not be mutated.
[ "Initialize an empty dictionary for counts.", "Iterate over each team string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_upper_7(teams): counts = {} for team in teams: cleaned = team.strip().upper() if len(cleaned) >= 7: 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 less than or equal to 24, sorts the kept records by 'quality' in ascending order, and returns a list of the 'identifier' values from the sorted records. The input list must not be mutated.
[ "Filter the list to keep records with quality <= 24.", "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_24_ascending(records): kept = [row for row in records if row["quality"] <= 24] 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 containing 'team' and 'units', keeps only entries where 'units' is at least 2, sums the retained 'units' grouped by 'team', and returns a dictionary mapping each team to its total. The input list must not be mutated.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add its units to the total for its team.", "Return the totals dictionary." ]
def total_units_by_team_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["team"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each containing 'team' and 'units', computes the average units per team, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying team to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total units per team, one for count per team.", "Iterate over each record, updating totals and counts for its team.", "Compute the average for each team as total divided by count.", "Return a dictionary of teams whose average is >= 12." ]
def qualifying_units_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 9, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 9), 'second_ahead' (second minus first > 9), and 'within_margin' (otherwise). The input lists must not be mu...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over paired elements using zip; for each pair, determine which category applies and increment the corresponding count.", "Return the dictionary." ]
def compare_pairs_with_margin_9_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 9: counts["first_ahead"] += 1 elif right - left > 9: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 1 within each inner list, adds 19 to each retained integer, and returns a new nested list preserving the original row order and structure. The input must not be mutated.
[ "For each inner list, filter to keep values >= 1.", "Add 19 to each kept value.", "Collect the transformed inner lists into a new outer list.", "Return the new nested list." ]
def transform_rows_2_19_1(rows): return [[value + 19 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each containing a 'team' key and a 'values' key that is a list of integers, returns a list of 'team' values for which the sum of the integers in 'values' exceeds 63, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 63, append the record's 'team' to the result list.", "Return the result list." ]
def teams_over_total_63(records): return [row["team"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of team counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 13, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated.
[ "Initialize an empty result dictionary.", "Compute the union of keys from both dictionaries.", "For each key, sum the values (using .get with default 0).", "If the total >= 13, add the key and total to the result dictionary; return it." ]
def combine_team_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears among those with length at least 7, returning a dictionary of those counts. The input list must not be mutated.
[ "Initialize an empty dictionary for counts.", "Iterate over each group string, strip and convert to uppercase.", "If the cleaned string length is at least 7, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_groups_upper_7(groups): counts = {} for group in groups: cleaned = group.strip().upper() if len(cleaned) >= 7: 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 less than or equal to 24, sorts the kept records by 'quality' in ascending order, and returns a list of the 'label' values from the sorted records. The input list must not be mutated.
[ "Filter the list to keep records with quality <= 24.", "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_24_ascending(records): kept = [row for row in records if row["quality"] <= 24] 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 containing 'group' and 'units', keeps only entries where 'units' is at least 2, sums the retained 'units' grouped by 'group', and returns a dictionary mapping each group to its total. The input list must not be mutated.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 2, add its units to the total for its group.", "Return the totals dictionary." ]
def total_units_by_group_min_2(records): totals = {} for row in records: if row["units"] >= 2: group = row["group"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each containing 'group' and 'units', computes the average units per group, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying group to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total units per group, one for count per group.", "Iterate over each record, updating totals and counts for its group.", "Compute the average for each group as total divided by count.", "Return a dictionary of groups whose average is >= 12." ]
def qualifying_units_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 10, and returns a dictionary with counts for three categories: 'first_ahead' (first minus second > 10), 'second_ahead' (second minus first > 10), and 'within_margin' (otherwise). The input lists must not be...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over paired elements using zip; for each pair, determine which category applies and increment the corresponding count.", "Return the dictionary." ]
def compare_pairs_with_margin_10_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 10: counts["first_ahead"] += 1 elif right - left > 10: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 1 within each inner list, multiplies each retained integer by 20, and returns a new nested list preserving the original row order and structure. The input must not be mutated.
[ "For each inner list, filter to keep values >= 1.", "Multiply each kept value by 20.", "Collect the transformed inner lists into a new outer list.", "Return the new nested list." ]
def transform_rows_0_20_1(rows): return [[value * 20 for value in row if value >= 1] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each containing a 'group' key and a 'values' key that is a list of integers, returns a list of 'group' values for which the sum of the integers in 'values' exceeds 63, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 63, append the record's 'group' to the result list.", "Return the result list." ]
def groups_over_total_63(records): return [row["group"] for row in records if sum(row["values"]) > 63]
task_code
Write a Python function that takes two dictionaries of group counts, sums the values over the union of keys (treating missing keys as 0), retains only those totals that are at least 13, and returns a new dictionary with those key-total pairs. The input dictionaries must not be mutated.
[ "Initialize an empty result dictionary.", "Compute the union of keys from both dictionaries.", "For each key, sum the values (using .get with default 0).", "If the total >= 13, add the key and total to the result dictionary; return it." ]
def combine_group_counts_min_13(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 13: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips leading/trailing whitespace and converts each complete string to lowercase, then counts how many times each normalized string appears among those with length at least 8, returning a dictionary of those counts. The input list must not be mutated.
[ "Initialize an empty dictionary for counts.", "Iterate over each tag string, strip and convert to lowercase.", "If the cleaned string length is at least 8, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_lower_8(tags): counts = {} for tag in tags: cleaned = tag.strip().lower() if len(cleaned) >= 8: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' value is less than or equal to 24, sorts the kept records by 'rank' in ascending order, and returns a list of the 'title' values from the sorted records. The input list must not be mutated.
[ "Filter the list to keep records with rank <= 24.", "Sort the filtered list by the 'rank' key in ascending order.", "Extract the 'title' values from the sorted records into a new list.", "Return the list of titles." ]
def select_titles_by_rank_24_ascending(records): kept = [row for row in records if row["rank"] <= 24] kept = sorted(kept, key=lambda row: row["rank"], reverse=False) return [row["title"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each containing 'tag' and 'points', keeps only entries where 'points' is at least 2, sums the retained 'points' grouped by 'tag', and returns a dictionary mapping each tag to its total. The input list must not be mutated.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 2, add its points to the total for its tag.", "Return the totals dictionary." ]
def total_points_by_tag_min_2(records): totals = {} for row in records: if row["points"] >= 2: group = row["tag"] totals[group] = totals.get(group, 0) + row["points"] return totals
task_code
Write a Python function that takes a list of dictionaries each containing 'tag' and 'points', computes the average points per tag, retains only those averages that are at least 12, and returns a dictionary mapping each qualifying tag to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points per tag, one for count per tag.", "Iterate over each record, updating totals and counts for its tag.", "Compute the average for each tag as total divided by count.", "Return a dictionary of tags whose average is >= 12." ]
def qualifying_points_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["points"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...