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 team strings, strips whitespace and converts each to lowercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each team string, strip and lowercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_teams_lower_10(teams): counts = {} for team in teams: cleaned = team.strip().lower() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'score' key is <= 26, sorts the kept records by 'score' in ascending order, returns a list of the 'identifier' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with score <= 26.", "Sort the filtered list by score in ascending order.", "Extract the 'identifier' value from each sorted record.", "Return the list of identifiers." ]
def select_identifiers_by_score_26_ascending(records): kept = [row for row in records if row["score"] <= 26] 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 'hours' keys, keeps only entries where 'hours' is at least 3, sums the retained hours grouped by team, returns a new dictionary mapping team to total hours, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if hours >= 3, add hours to the team's total.", "Return the totals dictionary." ]
def total_hours_by_team_min_3(records): totals = {} for row in records: if row["hours"] >= 3: group = row["team"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'hours' keys, computes the average hours per team, keeps only those averages that are at least 13, returns a dictionary mapping team to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total hours and count per team.", "Compute average for each team as total divided by count.", "Return a dictionary of teams whose average >= 13." ]
def qualifying_hours_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 49, counts how many pairs have the first value more than 49 greater than the second, how many have the second more than 49 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 49, increment 'first_ahead'; else if right - left > 49, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_49_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 49: counts["first_ahead"] += 1 elif right - left > 49: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are at least 2 and multiplies each kept integer by 14, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are >= 2, each multiplied by 14.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_0_14_2(rows): return [[value * 14 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'values' (a list of integers), returns a list of 'team' values for which the sum of its 'values' list exceeds 68, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 68, append the 'team' value.", "Return the result list." ]
def teams_over_total_68(records): return [row["team"] for row in records if sum(row["values"]) > 68]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 18, 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 as first.get(key,0) + second.get(key,0).", "If total >= 18, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_team_counts_min_18(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 18: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips whitespace and converts each to lowercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each group string, strip and lowercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_groups_lower_10(groups): counts = {} for group in groups: cleaned = group.strip().lower() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'score' key is <= 26, sorts the kept records by 'score' in ascending order, returns a list of the 'label' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with score <= 26.", "Sort the filtered list by score in ascending order.", "Extract the 'label' value from each sorted record.", "Return the list of labels." ]
def select_labels_by_score_26_ascending(records): kept = [row for row in records if row["score"] <= 26] 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 'hours' keys, keeps only entries where 'hours' is at least 3, sums the retained hours grouped by group, returns a new dictionary mapping group to total hours, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if hours >= 3, add hours to the group's total.", "Return the totals dictionary." ]
def total_hours_by_group_min_3(records): totals = {} for row in records: if row["hours"] >= 3: group = row["group"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'hours' keys, computes the average hours per group, keeps only those averages that are at least 13, returns a dictionary mapping group to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total hours and count per group.", "Compute average for each group as total divided by count.", "Return a dictionary of groups whose average >= 13." ]
def qualifying_hours_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 50, counts how many pairs have the first value more than 50 greater than the second, how many have the second more than 50 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 50, increment 'first_ahead'; else if right - left > 50, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_50_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 50: counts["first_ahead"] += 1 elif right - left > 50: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are greater than 2, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are > 2.", "Append the filtered row to the result.", "Return the result list." ]
def transform_rows_1_14_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'values' (a list of integers), returns a list of 'group' values for which the sum of its 'values' list exceeds 68, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 68, append the 'group' value.", "Return the result list." ]
def groups_over_total_68(records): return [row["group"] for row in records if sum(row["values"]) > 68]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 18, 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 as first.get(key,0) + second.get(key,0).", "If total >= 18, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_group_counts_min_18(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 18: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips whitespace and converts each to uppercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each tag string, strip and uppercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_tags_upper_10(tags): counts = {} for tag in tags: cleaned = tag.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 26, sorts the kept records by 'priority' in ascending order, returns a list of the 'title' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with priority <= 26.", "Sort the filtered list by priority in ascending order.", "Extract the 'title' value from each sorted record.", "Return the list of titles." ]
def select_titles_by_priority_26_ascending(records): kept = [row for row in records if row["priority"] <= 26] 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 'units' keys, keeps only entries where 'units' is at least 3, sums the retained units grouped by tag, returns a new dictionary mapping tag to total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if units >= 3, add units to the tag's total.", "Return the totals dictionary." ]
def total_units_by_tag_min_3(records): totals = {} for row in records: if row["units"] >= 3: group = row["tag"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'units' keys, computes the average units per tag, keeps only those averages that are at least 13, returns a dictionary mapping tag to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total units and count per tag.", "Compute average for each tag as total divided by count.", "Return a dictionary of tags whose average >= 13." ]
def qualifying_units_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 51, counts how many pairs have the first value more than 51 greater than the second, how many have the second more than 51 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 51, increment 'first_ahead'; else if right - left > 51, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_51_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 51: counts["first_ahead"] += 1 elif right - left > 51: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are at least 2 and adds 14 to each kept integer, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are >= 2, each increased by 14.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_2_14_2(rows): return [[value + 14 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'values' (a list of integers), returns a list of 'tag' values for which the sum of its 'values' list exceeds 69, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 69, append the 'tag' value.", "Return the result list." ]
def tags_over_total_69(records): return [row["tag"] for row in records if sum(row["values"]) > 69]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 19, 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 as first.get(key,0) + second.get(key,0).", "If total >= 19, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of label strings, strips whitespace and converts each to uppercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each label string, strip and uppercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_labels_upper_10(labels): counts = {} for label in labels: cleaned = label.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 26, sorts the kept records by 'priority' in ascending order, returns a list of the 'name' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with priority <= 26.", "Sort the filtered list by priority in ascending order.", "Extract the 'name' value from each sorted record.", "Return the list of names." ]
def select_names_by_priority_26_ascending(records): kept = [row for row in records if row["priority"] <= 26] 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 'units' keys, keeps only entries where 'units' is at least 3, sums the retained units grouped by label, returns a new dictionary mapping label to total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if units >= 3, add units to the label's total.", "Return the totals dictionary." ]
def total_units_by_label_min_3(records): totals = {} for row in records: if row["units"] >= 3: group = row["label"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'units' keys, computes the average units per label, keeps only those averages that are at least 13, returns a dictionary mapping label to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total units and count per label.", "Compute average for each label as total divided by count.", "Return a dictionary of labels whose average >= 13." ]
def qualifying_units_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 52, counts how many pairs have the first value more than 52 greater than the second, how many have the second more than 52 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 52, increment 'first_ahead'; else if right - left > 52, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_52_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 52: counts["first_ahead"] += 1 elif right - left > 52: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are at least 2 and multiplies each kept integer by 15, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are >= 2, each multiplied by 15.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_0_15_2(rows): return [[value * 15 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'values' (a list of integers), returns a list of 'label' values for which the sum of its 'values' list exceeds 69, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 69, append the 'label' value.", "Return the result list." ]
def labels_over_total_69(records): return [row["label"] for row in records if sum(row["values"]) > 69]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 19, 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 as first.get(key,0) + second.get(key,0).", "If total >= 19, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of status strings, strips whitespace and converts each to uppercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each status string, strip and uppercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_statuss_upper_10(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 26, sorts the kept records by 'priority' in ascending order, returns a list of the 'identifier' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with priority <= 26.", "Sort the filtered list by priority in ascending order.", "Extract the 'identifier' value from each sorted record.", "Return the list of identifiers." ]
def select_identifiers_by_priority_26_ascending(records): kept = [row for row in records if row["priority"] <= 26] 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 'units' keys, keeps only entries where 'units' is at least 3, sums the retained units grouped by status, returns a new dictionary mapping status to total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if units >= 3, add units to the status's total.", "Return the totals dictionary." ]
def total_units_by_status_min_3(records): totals = {} for row in records: if row["units"] >= 3: group = row["status"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'status' and 'units' keys, computes the average units per status, keeps only those averages that are at least 13, returns a dictionary mapping status to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total units and count per status.", "Compute average for each status as total divided by count.", "Return a dictionary of statuses whose average >= 13." ]
def qualifying_units_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 53, counts how many pairs have the first value more than 53 greater than the second, how many have the second more than 53 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 53, increment 'first_ahead'; else if right - left > 53, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_53_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 53: counts["first_ahead"] += 1 elif right - left > 53: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are greater than 2, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are > 2.", "Append the filtered row to the result.", "Return the result list." ]
def transform_rows_1_15_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'status' and 'values' (a list of integers), returns a list of 'status' values for which the sum of its 'values' list exceeds 69, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 69, append the 'status' value.", "Return the result list." ]
def statuss_over_total_69(records): return [row["status"] for row in records if sum(row["values"]) > 69]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 19, 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 as first.get(key,0) + second.get(key,0).", "If total >= 19, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_status_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of category strings, strips whitespace and converts each to uppercase, counts how many normalized strings have length at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Loop over each category string, strip and uppercase it.", "If the cleaned string length is >= 10, increment its count in the dictionary.", "Return the counts dictionary." ]
def count_clean_categorys_upper_10(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'priority' key is <= 26, sorts the kept records by 'priority' in ascending order, returns a list of the 'label' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with priority <= 26.", "Sort the filtered list by priority in ascending order.", "Extract the 'label' value from each sorted record.", "Return the list of labels." ]
def select_labels_by_priority_26_ascending(records): kept = [row for row in records if row["priority"] <= 26] 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 'units' keys, keeps only entries where 'units' is at least 3, sums the retained units grouped by category, returns a new dictionary mapping category to total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop over each record; if units >= 3, add units to the category's total.", "Return the totals dictionary." ]
def total_units_by_category_min_3(records): totals = {} for row in records: if row["units"] >= 3: group = row["category"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'units' keys, computes the average units per category, keeps only those averages that are at least 13, returns a dictionary mapping category to its average, and does not mutate the input list.
[ "Initialize two dictionaries for totals and counts.", "Loop over each record, accumulating total units and count per category.", "Compute average for each category as total divided by count.", "Return a dictionary of categories whose average >= 13." ]
def qualifying_units_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] totals[group] = totals.get(group, 0) + row["units"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / cou...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 54, counts how many pairs have the first value more than 54 greater than the second, how many have the second more than 54 greater than the first, and how many are within that margin, returns a dictionary with keys '...
[ "Initialize counts dictionary with three keys set to 0.", "Loop over paired elements using zip.", "If left - right > 54, increment 'first_ahead'; else if right - left > 54, increment 'second_ahead'; else increment 'within_margin'.", "Return the counts dictionary." ]
def compare_pairs_with_margin_54_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 54: counts["first_ahead"] += 1 elif right - left > 54: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list keeps only integers that are at least 2 and adds 15 to each kept integer, returns a new nested list preserving the order of rows and retained elements, and does not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list of values that are >= 2, each increased by 15.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_2_15_2(rows): return [[value + 15 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'values' (a list of integers), returns a list of 'category' values for which the sum of its 'values' list exceeds 69, preserving original order, and does not mutate the input list.
[ "Initialize an empty result list.", "Loop over each record; if sum of its 'values' > 69, append the 'category' value.", "Return the result list." ]
def categorys_over_total_69(records): return [row["category"] for row in records if sum(row["values"]) > 69]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those sums that are at least 19, 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 as first.get(key,0) + second.get(key,0).", "If total >= 19, add key and total to result dictionary.", "Return the result dictionary." ]
def combine_category_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: 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 string to uppercase, filters to keep only those with length at least 10, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each topic string: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 10, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_10(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'quality' key is <= 26, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with quality <= 26.", "Sort the filtered list by the 'quality' key in ascending order.", "Extract the 'title' value from each sorted record into a new list.", "Return the list of titles." ]
def select_titles_by_quality_26_ascending(records): kept = [row for row in records if row["quality"] <= 26] 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 with keys 'topic' and 'units', keeps only those entries where 'units' is at least 3, and returns a dictionary mapping each topic to the sum of its retained units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 3, add its units to the total for its topic.", "Return the totals dictionary." ]
def total_units_by_topic_min_3(records): totals = {} for row in records: if row["units"] >= 3: 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 with keys 'topic' and 'units', computes the average units per topic, and returns a dictionary mapping each topic to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per topic, one for count per topic.", "Iterate over each record: accumulate total units and count for its topic.", "Compute average for each topic as total / count.", "Return a dictionary of topics whose average is >= 13." ]
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 using a margin of 55, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 55, increment first_ahead; else if right - left > 55, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_55_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 55: counts["first_ahead"] += 1 elif right - left > 55: 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 2 and multiplies each retained integer by 16, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list of values that are >= 2, each multiplied by 16.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_0_16_2(rows): return [[value * 16 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'topic' and 'values' (a list of integers), and returns a list of 'topic' values for which the sum of the integers in 'values' exceeds 69, preserving 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 > 69, append the record's 'topic' to the result.", "Return the result list." ]
def topics_over_total_69(records): return [row["topic"] for row in records if sum(row["values"]) > 69]
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 where the total is at least 19. 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 >= 19, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_topic_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: 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 string to uppercase, filters to keep only those with length at least 10, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each region: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 10, increment its count.", "Return the dictionary." ]
def count_clean_regions_upper_10(regions): counts = {} for region in regions: cleaned = region.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'quality' key is <= 26, sorts the kept records by 'quality' in ascending order, and returns a list of the 'name' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with quality <= 26.", "Sort the filtered list by 'quality' in ascending order.", "Extract the 'name' value from each sorted record.", "Return the list of names." ]
def select_names_by_quality_26_ascending(records): kept = [row for row in records if row["quality"] <= 26] 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 with keys 'region' and 'units', keeps only those entries where 'units' is at least 3, and returns a dictionary mapping each region to the sum of its retained units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 3, add its units to the total for its region.", "Return the totals dictionary." ]
def total_units_by_region_min_3(records): totals = {} for row in records: if row["units"] >= 3: 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 with keys 'region' and 'units', computes the average units per region, and returns a dictionary mapping each region to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per region, one for count per region.", "Iterate over each record: accumulate total units and count for its region.", "Compute average for each region as total / count.", "Return a dictionary of regions whose average is >= 13." ]
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 56, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 56, increment first_ahead; else if right - left > 56, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_56_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 56: counts["first_ahead"] += 1 elif right - left > 56: 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 greater than 2, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list containing only values > 2.", "Append the filtered row to the result.", "Return the result list." ]
def transform_rows_1_16_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'region' and 'values' (a list of integers), and returns a list of 'region' values for which the sum of the integers in 'values' exceeds 69, preserving 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 > 69, append the record's 'region' to the result.", "Return the result list." ]
def regions_over_total_69(records): return [row["region"] for row in records if sum(row["values"]) > 69]
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 where the total is at least 19. 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 >= 19, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_region_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of team strings, strips leading/trailing whitespace and converts each string to uppercase, filters to keep only those with length at least 10, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each team: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 10, increment its count.", "Return the dictionary." ]
def count_clean_teams_upper_10(teams): counts = {} for team in teams: cleaned = team.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'quality' key is <= 26, sorts the kept records by 'quality' in ascending order, and returns a list of the 'identifier' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with quality <= 26.", "Sort the filtered list by 'quality' in ascending order.", "Extract the 'identifier' value from each sorted record.", "Return the list of identifiers." ]
def select_identifiers_by_quality_26_ascending(records): kept = [row for row in records if row["quality"] <= 26] 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 with keys 'team' and 'units', keeps only those entries where 'units' is at least 3, and returns a dictionary mapping each team to the sum of its retained units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 3, add its units to the total for its team.", "Return the totals dictionary." ]
def total_units_by_team_min_3(records): totals = {} for row in records: if row["units"] >= 3: 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 with keys 'team' and 'units', computes the average units per team, and returns a dictionary mapping each team to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per team, one for count per team.", "Iterate over each record: accumulate total units and count for its team.", "Compute average for each team as total / count.", "Return a dictionary of teams whose average is >= 13." ]
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 57, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 57, increment first_ahead; else if right - left > 57, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_57_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 57: counts["first_ahead"] += 1 elif right - left > 57: 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 2 and adds 16 to each retained integer, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list of values that are >= 2, each with 16 added.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_2_16_2(rows): return [[value + 16 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'team' and 'values' (a list of integers), and returns a list of 'team' values for which the sum of the integers in 'values' exceeds 69, preserving 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 > 69, append the record's 'team' to the result.", "Return the result list." ]
def teams_over_total_69(records): return [row["team"] for row in records if sum(row["values"]) > 69]
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 where the total is at least 19. 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 >= 19, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_team_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips leading/trailing whitespace and converts each string to uppercase, filters to keep only those with length at least 10, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each group: strip whitespace and convert to uppercase.", "If the cleaned string length is at least 10, increment its count.", "Return the dictionary." ]
def count_clean_groups_upper_10(groups): counts = {} for group in groups: cleaned = group.strip().upper() if len(cleaned) >= 10: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'quality' key is <= 26, sorts the kept records by 'quality' in ascending order, and returns a list of the 'label' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with quality <= 26.", "Sort the filtered list by 'quality' in ascending order.", "Extract the 'label' value from each sorted record.", "Return the list of labels." ]
def select_labels_by_quality_26_ascending(records): kept = [row for row in records if row["quality"] <= 26] 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 with keys 'group' and 'units', keeps only those entries where 'units' is at least 3, and returns a dictionary mapping each group to the sum of its retained units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 3, add its units to the total for its group.", "Return the totals dictionary." ]
def total_units_by_group_min_3(records): totals = {} for row in records: if row["units"] >= 3: 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 with keys 'group' and 'units', computes the average units per group, and returns a dictionary mapping each group to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per group, one for count per group.", "Iterate over each record: accumulate total units and count for its group.", "Compute average for each group as total / count.", "Return a dictionary of groups whose average is >= 13." ]
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 58, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 58, increment first_ahead; else if right - left > 58, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_58_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 58: counts["first_ahead"] += 1 elif right - left > 58: 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 2 and multiplies each retained integer by 17, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list of values that are >= 2, each multiplied by 17.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_0_17_2(rows): return [[value * 17 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'group' and 'values' (a list of integers), and returns a list of 'group' values for which the sum of the integers in 'values' exceeds 69, preserving 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 > 69, append the record's 'group' to the result.", "Return the result list." ]
def groups_over_total_69(records): return [row["group"] for row in records if sum(row["values"]) > 69]
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 where the total is at least 19. 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 >= 19, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_group_counts_min_19(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 19: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips leading/trailing whitespace and converts each string to lowercase, filters to keep only those with length at least 11, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each tag: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 11, increment its count.", "Return the dictionary." ]
def count_clean_tags_lower_11(tags): counts = {} for tag in tags: cleaned = tag.strip().lower() if len(cleaned) >= 11: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'rank' key is <= 26, sorts the kept records by 'rank' in ascending order, and returns a list of the 'title' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with rank <= 26.", "Sort the filtered list by 'rank' in ascending order.", "Extract the 'title' value from each sorted record.", "Return the list of titles." ]
def select_titles_by_rank_26_ascending(records): kept = [row for row in records if row["rank"] <= 26] 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 with keys 'tag' and 'points', keeps only those entries where 'points' is at least 3, and returns a dictionary mapping each tag to the sum of its retained points. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if points >= 3, add its points to the total for its tag.", "Return the totals dictionary." ]
def total_points_by_tag_min_3(records): totals = {} for row in records: if row["points"] >= 3: 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 with keys 'tag' and 'points', computes the average points per tag, and returns a dictionary mapping each tag to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total points per tag, one for count per tag.", "Iterate over each record: accumulate total points and count for its tag.", "Compute average for each tag as total / count.", "Return a dictionary of tags whose average is >= 13." ]
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] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 59, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 59, increment first_ahead; else if right - left > 59, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_59_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 59: counts["first_ahead"] += 1 elif right - left > 59: 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 greater than 2, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list containing only values > 2.", "Append the filtered row to the result.", "Return the result list." ]
def transform_rows_1_17_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'tag' and 'values' (a list of integers), and returns a list of 'tag' values for which the sum of the integers in 'values' exceeds 70, preserving 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 > 70, append the record's 'tag' to the result.", "Return the result list." ]
def tags_over_total_70(records): return [row["tag"] for row in records if sum(row["values"]) > 70]
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 where the total is at least 20. 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 >= 20, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_20(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 20: result[key] = total return result
task_code
Write a Python function that takes a list of label strings, strips leading/trailing whitespace and converts each string to lowercase, filters to keep only those with length at least 11, and returns a dictionary mapping each such normalized string to its count. Do not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each label: strip whitespace and convert to lowercase.", "If the cleaned string length is at least 11, increment its count.", "Return the dictionary." ]
def count_clean_labels_lower_11(labels): counts = {} for label in labels: cleaned = label.strip().lower() if len(cleaned) >= 11: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'rank' key is <= 26, sorts the kept records by 'rank' in ascending order, and returns a list of the 'name' values from the sorted records. Do not mutate the input list.
[ "Filter the list to include only records with rank <= 26.", "Sort the filtered list by 'rank' in ascending order.", "Extract the 'name' value from each sorted record.", "Return the list of names." ]
def select_names_by_rank_26_ascending(records): kept = [row for row in records if row["rank"] <= 26] kept = sorted(kept, key=lambda row: row["rank"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'label' and 'points', keeps only those entries where 'points' is at least 3, and returns a dictionary mapping each label to the sum of its retained points. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if points >= 3, add its points to the total for its label.", "Return the totals dictionary." ]
def total_points_by_label_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["label"] totals[group] = totals.get(group, 0) + row["points"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'label' and 'points', computes the average points per label, and returns a dictionary mapping each label to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total points per label, one for count per label.", "Iterate over each record: accumulate total points and count for its label.", "Compute average for each label as total / count.", "Return a dictionary of labels whose average is >= 13." ]
def qualifying_points_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] 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[...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 60, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input lists.
[ "Initialize a dictionary with three counts set to 0.", "Iterate over paired elements using zip.", "If left - right > 60, increment first_ahead; else if right - left > 60, increment second_ahead; else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_60_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 60: counts["first_ahead"] += 1 elif right - left > 60: 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 2 and adds 17 to each retained integer, preserving the order of rows and values. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner row, create a new list of values that are >= 2, each with 17 added.", "Append the transformed row to the result.", "Return the result list." ]
def transform_rows_2_17_2(rows): return [[value + 17 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'label' and 'values' (a list of integers), and returns a list of 'label' values for which the sum of the integers in 'values' exceeds 70, preserving 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 > 70, append the record's 'label' to the result.", "Return the result list." ]
def labels_over_total_70(records): return [row["label"] for row in records if sum(row["values"]) > 70]
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 where the total is at least 20. 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 >= 20, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_20(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 20: 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 lowercase, keeps only those normalized strings whose length is at least 11, counts how many times each such normalized string appears, and returns a dictionary of those counts. The input li...
[ "Initialize an empty dictionary for counts.", "Iterate over each status string in the input list, strip whitespace and convert to lowercase.", "If the cleaned string has length >= 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_lower_11(statuss): counts = {} for status in statuss: cleaned = status.strip().lower() if len(cleaned) >= 11: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'identifier', keeps only those dictionaries where the value of 'rank' is <= 26, sorts the kept dictionaries by 'rank' in ascending order, and returns a list of the 'identifier' values from the sorted dictionaries. The input list must n...
[ "Filter the list to keep only dictionaries with rank <= 26.", "Sort the filtered list by the 'rank' key in ascending order.", "Extract the 'identifier' values from the sorted list into a new list.", "Return the list of identifiers." ]
def select_identifiers_by_rank_26_ascending(records): kept = [row for row in records if row["rank"] <= 26] kept = sorted(kept, key=lambda row: row["rank"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'status' and 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'status', and returns a new dictionary mapping each status to its total points. The input list must not be...
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 3, add points to the total for its status.", "Return the totals dictionary." ]
def total_points_by_status_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["status"] totals[group] = totals.get(group, 0) + row["points"] return totals
task_code
Write a Python function that takes a list of dictionaries, each with keys 'status' and 'points', computes the average points for each status, keeps only those averages that are at least 13, and returns a dictionary mapping each such status to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points per status, one for count per status.", "Iterate over each record, updating totals and counts for its status.", "Compute the average for each status as total / count.", "Return a dictionary of statuses whose average >= 13." ]
def qualifying_points_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] 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] / count...