type
stringclasses
1 value
task
stringlengths
137
560
plan
listlengths
2
4
code
stringlengths
98
383
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 61, counts how many pairs have the first value more than 61 greater than the second, how many have the second more than 61 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 61, increment first_ahead; else if right - left > 61, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_61_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 61: counts["first_ahead"] += 1 elif right - left > 61: 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, multiplies each kept integer by 18, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value * 18 for each value >= 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_18_2(rows): return [[value * 18 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'status' and 'values' (where 'values' is a list of integers), returns a list of the 'status' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'status' to the result.", "Return the result list." ]
def statuss_over_total_70(records): return [row["status"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping status strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not be...
[ "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_status_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 category 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 ...
[ "Initialize an empty dictionary for counts.", "Iterate over each category string, 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_categorys_lower_11(categorys): counts = {} for category in categorys: cleaned = category.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 'label', 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 'label' values from the sorted dictionaries. The input list must not be muta...
[ "Filter the list to keep only dictionaries with rank <= 26.", "Sort the filtered list by the 'rank' key in ascending order.", "Extract the 'label' values from the sorted list into a new list.", "Return the list of labels." ]
def select_labels_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["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'category' and 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'category', and returns a new dictionary mapping each category to its total points. The input list must ...
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 3, add points to the total for its category.", "Return the totals dictionary." ]
def total_points_by_category_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["category"] 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 'category' and 'points', computes the average points for each category, keeps only those averages that are at least 13, and returns a dictionary mapping each such category to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points per category, one for count per category.", "Iterate over each record, updating totals and counts for its category.", "Compute the average for each category as total / count.", "Return a dictionary of categories whose average >= 13." ]
def qualifying_points_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] 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] / c...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 62, counts how many pairs have the first value more than 62 greater than the second, how many have the second more than 62 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 62, increment first_ahead; else if right - left > 62, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_62_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 62: counts["first_ahead"] += 1 elif right - left > 62: 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, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_18_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'category' and 'values' (where 'values' is a list of integers), returns a list of the 'category' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated...
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'category' to the result.", "Return the result list." ]
def categorys_over_total_70(records): return [row["category"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping category strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not ...
[ "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_category_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 topic 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 lis...
[ "Initialize an empty dictionary for counts.", "Iterate over each topic string, 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_topics_lower_11(topics): counts = {} for topic in topics: cleaned = topic.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 'weight' and 'title', keeps only those dictionaries where the value of 'weight' is <= 26, sorts the kept dictionaries by 'weight' in ascending order, and returns a list of the 'title' values from the sorted dictionaries. The input list must not b...
[ "Filter the list to keep only dictionaries with weight <= 26.", "Sort the filtered list by the 'weight' 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_weight_26_ascending(records): kept = [row for row in records if row["weight"] <= 26] kept = sorted(kept, key=lambda row: row["weight"], 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 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'topic', and returns a new dictionary mapping each topic to its total points. The input list must not be mu...
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 3, add points to the total for its topic.", "Return the totals dictionary." ]
def total_points_by_topic_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["topic"] 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 'topic' and 'points', computes the average points for each topic, keeps only those averages that are at least 13, and returns a dictionary mapping each such topic to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points 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 / count.", "Return a dictionary of topics whose average >= 13." ]
def qualifying_points_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] 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 lists of integers, compares each pair of corresponding values using a margin of 63, counts how many pairs have the first value more than 63 greater than the second, how many have the second more than 63 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 63, increment first_ahead; else if right - left > 63, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_63_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 63: counts["first_ahead"] += 1 elif right - left > 63: 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, adds 18 to each kept integer, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value + 18 for each value >= 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_18_2(rows): return [[value + 18 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'values' (where 'values' is a list of integers), returns a list of the 'topic' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'topic' to the result.", "Return the result list." ]
def topics_over_total_70(records): return [row["topic"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping topic strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not be ...
[ "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_topic_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 region 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 region string, 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_regions_lower_11(regions): counts = {} for region in regions: cleaned = region.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 'weight' and 'name', keeps only those dictionaries where the value of 'weight' is <= 26, sorts the kept dictionaries by 'weight' in ascending order, and returns a list of the 'name' values from the sorted dictionaries. The input list must not be ...
[ "Filter the list to keep only dictionaries with weight <= 26.", "Sort the filtered list by the 'weight' 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_weight_26_ascending(records): kept = [row for row in records if row["weight"] <= 26] kept = sorted(kept, key=lambda row: row["weight"], 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 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'region', and returns a new dictionary mapping each region 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 region.", "Return the totals dictionary." ]
def total_points_by_region_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["region"] 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 'region' and 'points', computes the average points for each region, keeps only those averages that are at least 13, and returns a dictionary mapping each such region to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points per region, one for count per region.", "Iterate over each record, updating totals and counts for its region.", "Compute the average for each region as total / count.", "Return a dictionary of regions whose average >= 13." ]
def qualifying_points_averages_by_region(records): totals = {} counts = {} for row in records: group = row["region"] 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...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 64, counts how many pairs have the first value more than 64 greater than the second, how many have the second more than 64 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 64, increment first_ahead; else if right - left > 64, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_64_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 64: counts["first_ahead"] += 1 elif right - left > 64: 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, multiplies each kept integer by 19, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value * 19 for each value >= 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_19_2(rows): return [[value * 19 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'region' and 'values' (where 'values' is a list of integers), returns a list of the 'region' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'region' to the result.", "Return the result list." ]
def regions_over_total_70(records): return [row["region"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping region strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not be...
[ "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_region_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 team 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 list...
[ "Initialize an empty dictionary for counts.", "Iterate over each team string, 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_teams_lower_11(teams): counts = {} for team in teams: cleaned = team.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 'weight' and 'identifier', keeps only those dictionaries where the value of 'weight' is <= 26, sorts the kept dictionaries by 'weight' in ascending order, and returns a list of the 'identifier' values from the sorted dictionaries. The input list ...
[ "Filter the list to keep only dictionaries with weight <= 26.", "Sort the filtered list by the 'weight' 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_weight_26_ascending(records): kept = [row for row in records if row["weight"] <= 26] kept = sorted(kept, key=lambda row: row["weight"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'team' and 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'team', and returns a new dictionary mapping each team to its total points. The input list must not be mutat...
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 3, add points to the total for its team.", "Return the totals dictionary." ]
def total_points_by_team_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["team"] 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 'team' and 'points', computes the average points for each team, keeps only those averages that are at least 13, and returns a dictionary mapping each such team to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points 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 / count.", "Return a dictionary of teams whose average >= 13." ]
def qualifying_points_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] 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 lists of integers, compares each pair of corresponding values using a margin of 65, counts how many pairs have the first value more than 65 greater than the second, how many have the second more than 65 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 65, increment first_ahead; else if right - left > 65, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_65_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 65: counts["first_ahead"] += 1 elif right - left > 65: 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, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_19_2(rows): return [[value for value in row if value > 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (where 'values' is a list of integers), returns a list of the 'team' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'team' to the result.", "Return the result list." ]
def teams_over_total_70(records): return [row["team"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping team strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not be m...
[ "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_team_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 group 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 lis...
[ "Initialize an empty dictionary for counts.", "Iterate over each group string, 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_groups_lower_11(groups): counts = {} for group in groups: cleaned = group.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 'weight' and 'label', keeps only those dictionaries where the value of 'weight' is <= 26, sorts the kept dictionaries by 'weight' in ascending order, and returns a list of the 'label' values from the sorted dictionaries. The input list must not b...
[ "Filter the list to keep only dictionaries with weight <= 26.", "Sort the filtered list by the 'weight' key in ascending order.", "Extract the 'label' values from the sorted list into a new list.", "Return the list of labels." ]
def select_labels_by_weight_26_ascending(records): kept = [row for row in records if row["weight"] <= 26] kept = sorted(kept, key=lambda row: row["weight"], reverse=False) return [row["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'group' and 'points', keeps only those entries where the value of 'points' is at least 3, sums the retained points grouped by the value of 'group', and returns a new dictionary mapping each group to its total points. The input list must not be mu...
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 3, add points to the total for its group.", "Return the totals dictionary." ]
def total_points_by_group_min_3(records): totals = {} for row in records: if row["points"] >= 3: group = row["group"] 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 'group' and 'points', computes the average points for each group, keeps only those averages that are at least 13, and returns a dictionary mapping each such group to its average. The input list must not be mutated.
[ "Initialize two dictionaries: one for total points 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 / count.", "Return a dictionary of groups whose average >= 13." ]
def qualifying_points_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] 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 lists of integers, compares each pair of corresponding values using a margin of 66, counts how many pairs have the first value more than 66 greater than the second, how many have the second more than 66 greater than the first, and how many are within that margin, and ...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs from both lists using zip.", "For each pair, check if left - right > 66, increment first_ahead; else if right - left > 66, increment second_ahead; else increment within_margin.", "Return the dictionary." ]
def compare_pairs_with_margin_66_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 66: counts["first_ahead"] += 1 elif right - left > 66: 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, adds 19 to each kept integer, and returns a new nested list preserving the structure and order. The input must not be mutated.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value + 19 for each value >= 2.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_19_2(rows): return [[value + 19 for value in row if value >= 2] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'group' and 'values' (where 'values' is a list of integers), returns a list of the 'group' values for those dictionaries where the sum of the integers in 'values' exceeds 70, preserving the original order. The input list must not be mutated.
[ "Initialize an empty result list.", "Iterate over each record; if sum of its 'values' > 70, append its 'group' to the result.", "Return the result list." ]
def groups_over_total_70(records): return [row["group"] for row in records if sum(row["values"]) > 70]
task_code
Write a Python function that takes two dictionaries mapping group strings to integer counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those sums that are at least 20, and returns a new dictionary with those key-sum pairs. The input dictionaries must not be ...
[ "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_group_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 tag strings, strips whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 11 appears. Return 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 in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_upper_11(tags): counts = {} for tag in tags: cleaned = tag.strip().upper() 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, filters to keep only those where the 'rating' key is <= 27, sorts the kept records by 'rating' in ascending order, and returns a list of the 'title' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['rating'] <= 27.", "Sort that list by the 'rating' 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_rating_27_ascending(records): kept = [row for row in records if row["rating"] <= 27] kept = sorted(kept, key=lambda row: row["rating"], reverse=False) return [row["title"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'tag' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'tag'. Return a dictionary mapping each tag to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its tag.", "Return the totals dictionary." ]
def total_cost_by_tag_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["tag"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'tag' and 'cost', computes the average cost 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 cost 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/count.", "Return a dictionary of tags whose average >= 13." ]
def qualifying_cost_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= 13...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 67, 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.", "For each pair, if left - right > 67 increment first_ahead, else if right - left > 67 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_67_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 67: counts["first_ahead"] += 1 elif right - left > 67: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers >= 2 in each inner list, multiplies each retained integer by 20, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value >= 2, each multiplied by 20.", "Append the transformed inner list to the result.", "Return the result." ]
def transform_rows_0_20_2(rows): return [[value * 20 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' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['tag'] to result.", "Return the result list." ]
def tags_over_total_71(records): return [row["tag"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: 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, then counts how many times each normalized string of length at least 11 appears. Return 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 in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_upper_11(labels): counts = {} for label in labels: cleaned = label.strip().upper() 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, filters to keep only those where the 'rating' key is <= 27, sorts the kept records by 'rating' in ascending order, and returns a list of the 'name' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['rating'] <= 27.", "Sort that list by the 'rating' key in ascending order.", "Extract the 'name' value from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_rating_27_ascending(records): kept = [row for row in records if row["rating"] <= 27] kept = sorted(kept, key=lambda row: row["rating"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'label' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'label'. Return a dictionary mapping each label to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its label.", "Return the totals dictionary." ]
def total_cost_by_label_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["label"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'label' and 'cost', computes the average cost 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 cost per label, one for count per label.", "Iterate over each record, updating totals and counts for its label.", "Compute the average for each label as total/count.", "Return a dictionary of labels whose average >= 13." ]
def qualifying_cost_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 68, 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.", "For each pair, if left - right > 68 increment first_ahead, else if right - left > 68 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_68_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 68: counts["first_ahead"] += 1 elif right - left > 68: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers greater than 2 in each inner list, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value > 2.", "Append the filtered inner list to the result.", "Return the result." ]
def transform_rows_1_20_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 'label' and 'values' (a list of integers), and returns a list of 'label' values for which the sum of the integers in 'values' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['label'] to result.", "Return the result list." ]
def labels_over_total_71(records): return [row["label"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: 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, then counts how many times each normalized string of length at least 11 appears. Return 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 status in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_upper_11(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() 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, filters to keep only those where the 'rating' key is <= 27, sorts the kept records by 'rating' in ascending order, and returns a list of the 'identifier' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['rating'] <= 27.", "Sort that list by the 'rating' key in ascending order.", "Extract the 'identifier' value from each sorted record into a new list.", "Return the list of identifiers." ]
def select_identifiers_by_rating_27_ascending(records): kept = [row for row in records if row["rating"] <= 27] kept = sorted(kept, key=lambda row: row["rating"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'status' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'status'. Return a dictionary mapping each status to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its status.", "Return the totals dictionary." ]
def total_cost_by_status_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["status"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'status' and 'cost', computes the average cost per status, and returns a dictionary mapping each status to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total cost 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_cost_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 69, 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.", "For each pair, if left - right > 69 increment first_ahead, else if right - left > 69 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_69_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 69: counts["first_ahead"] += 1 elif right - left > 69: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers >= 2 in each inner list, adds 20 to each retained integer, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value >= 2, each increased by 20.", "Append the transformed inner list to the result.", "Return the result." ]
def transform_rows_2_20_2(rows): return [[value + 20 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 'status' and 'values' (a list of integers), and returns a list of 'status' values for which the sum of the integers in 'values' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['status'] to result.", "Return the result list." ]
def statuss_over_total_71(records): return [row["status"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_status_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: 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, then counts how many times each normalized string of length at least 11 appears. Return 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 category in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_upper_11(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() 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, filters to keep only those where the 'rating' key is <= 27, sorts the kept records by 'rating' in ascending order, and returns a list of the 'label' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['rating'] <= 27.", "Sort that list by the 'rating' key in ascending order.", "Extract the 'label' value from each sorted record into a new list.", "Return the list of labels." ]
def select_labels_by_rating_27_ascending(records): kept = [row for row in records if row["rating"] <= 27] kept = sorted(kept, key=lambda row: row["rating"], reverse=False) return [row["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'category' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'category'. Return a dictionary mapping each category to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its category.", "Return the totals dictionary." ]
def total_cost_by_category_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["category"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'category' and 'cost', computes the average cost per category, and returns a dictionary mapping each category to its average only if that average is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total cost per category, one for count per category.", "Iterate over each record, updating totals and counts for its category.", "Compute the average for each category as total/count.", "Return a dictionary of categories whose average >= 13." ]
def qualifying_cost_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / count...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 70, 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.", "For each pair, if left - right > 70 increment first_ahead, else if right - left > 70 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_70_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 70: counts["first_ahead"] += 1 elif right - left > 70: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers >= 3 in each inner list, multiplies each retained integer by 2, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value >= 3, each multiplied by 2.", "Append the transformed inner list to the result.", "Return the result." ]
def transform_rows_0_2_3(rows): return [[value * 2 for value in row if value >= 3] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with keys 'category' and 'values' (a list of integers), and returns a list of 'category' values for which the sum of the integers in 'values' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['category'] to result.", "Return the result list." ]
def categorys_over_total_71(records): return [row["category"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_category_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: result[key] = total return result
task_code
Write a Python function that takes a list of topic strings, strips whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 11 appears. Return 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 in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_11(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() 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, filters to keep only those where the 'score' key is <= 27, sorts the kept records by 'score' in ascending order, and returns a list of the 'title' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['score'] <= 27.", "Sort that list by the 'score' 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_score_27_ascending(records): kept = [row for row in records if row["score"] <= 27] 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 with keys 'topic' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'topic'. Return a dictionary mapping each topic to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its topic.", "Return the totals dictionary." ]
def total_cost_by_topic_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["topic"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'topic' and 'cost', computes the average cost 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 cost 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/count.", "Return a dictionary of topics whose average >= 13." ]
def qualifying_cost_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 71, 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.", "For each pair, if left - right > 71 increment first_ahead, else if right - left > 71 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_71_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 71: counts["first_ahead"] += 1 elif right - left > 71: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers greater than 3 in each inner list, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value > 3.", "Append the filtered inner list to the result.", "Return the result." ]
def transform_rows_1_2_3(rows): return [[value for value in row if value > 3] 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' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['topic'] to result.", "Return the result list." ]
def topics_over_total_71(records): return [row["topic"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_topic_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips whitespace and converts each to uppercase, then counts how many times each normalized string of length at least 11 appears. Return 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 in the input list, strip and uppercase it.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_upper_11(regions): counts = {} for region in regions: cleaned = region.strip().upper() 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, filters to keep only those where the 'score' key is <= 27, sorts the kept records by 'score' in ascending order, and returns a list of the 'name' values from the sorted records. Do not mutate the input list.
[ "Create a list of records where record['score'] <= 27.", "Sort that list by the 'score' key in ascending order.", "Extract the 'name' value from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_score_27_ascending(records): kept = [row for row in records if row["score"] <= 27] kept = sorted(kept, key=lambda row: row["score"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries with keys 'region' and 'cost', filters to keep only entries where 'cost' >= 3, then sums the 'cost' values grouped by 'region'. Return a dictionary mapping each region to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if record['cost'] >= 3, add its cost to the total for its region.", "Return the totals dictionary." ]
def total_cost_by_region_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["region"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries with keys 'region' and 'cost', computes the average cost 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 cost per region, one for count per region.", "Iterate over each record, updating totals and counts for its region.", "Compute the average for each region as total/count.", "Return a dictionary of regions whose average >= 13." ]
def qualifying_cost_averages_by_region(records): totals = {} counts = {} for row in records: group = row["region"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values using a margin of 72, 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.", "For each pair, if left - right > 72 increment first_ahead, else if right - left > 72 increment second_ahead, else increment within_margin.", "Return the counts dictionary." ]
def compare_pairs_with_margin_72_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 72: counts["first_ahead"] += 1 elif right - left > 72: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers >= 3 in each inner list, adds 2 to each retained integer, and returns a new nested list preserving the original row structure and order. Do not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values where value >= 3, each increased by 2.", "Append the transformed inner list to the result.", "Return the result." ]
def transform_rows_2_2_3(rows): return [[value + 2 for value in row if value >= 3] 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' is greater than 71, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record; if sum(record['values']) > 71, append record['region'] to result.", "Return the result list." ]
def regions_over_total_71(records): return [row["region"] for row in records if sum(row["values"]) > 71]
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), and returns a new dictionary containing only those keys where the total is at least 21. 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 >= 21, add the key and total to a result dictionary.", "Return the result dictionary." ]
def combine_region_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: 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, but only includes those whose length is at least 11. Return a dictionary mapping each such normalized string to its cou...
[ "Initialize an empty dictionary for counts.", "Iterate over each team string in the input list, strip whitespace and convert to uppercase.", "If the cleaned string length is at least 11, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_upper_11(teams): counts = {} for team in teams: cleaned = team.strip().upper() 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 'score' and 'identifier', filters to keep only those where 'score' is <= 27, sorts the kept records by 'score' in ascending order, and returns a list of the 'identifier' values in that sorted order. Do not mutate the input list.
[ "Create a new list containing only records with score <= 27.", "Sort that list by the 'score' 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_score_27_ascending(records): kept = [row for row in records if row["score"] <= 27] kept = sorted(kept, key=lambda row: row["score"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'team' and 'cost', filters to keep only entries where 'cost' is at least 3, and then sums the 'cost' values grouped by 'team'. Return a dictionary mapping each team to its total cost. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if cost >= 3, add the cost to the team's running total.", "Return the totals dictionary." ]
def total_cost_by_team_min_3(records): totals = {} for row in records: if row["cost"] >= 3: group = row["team"] totals[group] = totals.get(group, 0) + row["cost"] return totals
task_code
Write a Python function that takes a list of dictionaries, each with keys 'team' and 'cost', computes the average cost per team, and returns a dictionary mapping each team to its average cost, but only for teams whose average cost is at least 13. Do not mutate the input list.
[ "Initialize two dictionaries: one for total cost per team, one for count per team.", "Iterate over each record, updating totals and counts for the team.", "Compute the average for each team as total divided by count.", "Return a dictionary of teams whose average is >= 13." ]
def qualifying_cost_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["cost"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of values (one from each list at the same position) using a margin of 73, 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 inp...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over pairs using zip; for each pair, compute the difference.", "If first minus second > 73, increment 'first_ahead'; else if second minus first > 73, increment 'second_ahead'; else increment 'within_margin'.", "Return the dictionary." ]
def compare_pairs_with_margin_73_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 73: counts["first_ahead"] += 1 elif right - left > 73: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers (list of rows), and for each row, retains only integers that are at least 3 and multiplies each retained integer by 3, preserving the row structure and order. Return a new nested list. Do not mutate the input.
[ "Initialize an empty list for the result.", "For each row in the input, create a new list by iterating over its elements.", "For each element, if it is >= 3, append element * 3 to the new row list.", "Append the new row to the result and return the result." ]
def transform_rows_0_3_3(rows): return [[value * 3 for value in row if value >= 3] for row in rows]
task_code
Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (a list of integers), and returns a list of 'team' values for which the sum of the integers in 'values' exceeds 71, preserving the original order. Do not mutate the input list.
[ "Initialize an empty list for selected teams.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 71, append the 'team' to the result list.", "Return the result list." ]
def teams_over_total_71(records): return [row["team"] for row in records if sum(row["values"]) > 71]
task_code
Write a Python function that takes two dictionaries mapping team names to integer counts, sums the counts over the union of keys (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 21. Do not mutate the input dictionaries.
[ "Initialize an empty result dictionary.", "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 21, add key: total to result.", "Return the result dictionary." ]
def combine_team_counts_min_21(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 21: result[key] = total return result