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 tag strings, strips leading/trailing whitespace and converts each complete string to uppercase, then counts how many times each normalized string appears, but only for those whose length is at least 13. Return a dictionary mapping each such normalized string to its count. Do...
[ "Initialize an empty dictionary for counts.", "Iterate over each tag string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_upper_13(tags): counts = {} for tag in tags: cleaned = tag.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'title', filters to keep only those where 'priority' is <= 28, sorts the kept records by 'priority' in ascending order, and returns a list of the 'title' values in that sorted order. Do not mutate the input list.
[ "Filter the list to keep records with priority <= 28.", "Sort the filtered list by priority in ascending order.", "Extract the 'title' values from the sorted list.", "Return the list of titles." ]
def select_titles_by_priority_28_ascending(records): kept = [row for row in records if row["priority"] <= 28] 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 keys 'tag' and 'units', and sums the 'units' for each 'tag', but only for entries where 'units' is at least 4. Return a dictionary mapping tag names to their total units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 4, add units to the tag's total.", "Return the totals dictionary." ]
def total_units_by_tag_min_4(records): totals = {} for row in records: if row["units"] >= 4: 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 keys 'tag' and 'units', computes the average units per tag across all entries, and returns a dictionary mapping tag names to their average units, but only for tags whose average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per tag, one for count per tag.", "Iterate over each record: add units to total and increment count for that tag.", "Compute average for each tag as total divided by count.", "Return a dictionary of tags with average >= 14." ]
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 lists of integers, compares each pair of corresponding values using a margin of 99, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value exceeds the second by more than 99, 'second_ahead' for pairs where the second exceeds the firs...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over pairs using zip: compute difference left - right.", "If left - right > 99, increment 'first_ahead'; else if right - left > 99, increment 'second_ahead'; else increment 'within_margin'.", "Return the dic...
def compare_pairs_with_margin_99_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 99: counts["first_ahead"] += 1 elif right - left > 99: 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, keeps only integers that are at least 3 and adds 11 to each retained integer, preserving the row order and structure. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list: iterate over values, keep those >= 3, add 11 to each.", "Append the transformed row to the result.", "Return the result." ]
def transform_rows_2_11_3(rows): return [[value + 11 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 'tag' and 'values' (a list of integers), and returns a list of 'tag' values for those records where the sum of the integers in 'values' exceeds 75, preserving the original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record: compute sum of its 'values' list.", "If the sum > 75, append the 'tag' value to the result.", "Return the result list." ]
def tags_over_total_75(records): return [row["tag"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 25. 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 >= 25, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 complete string to uppercase, then counts how many times each normalized string appears, but only for those whose length is at least 13. Return a dictionary mapping each such normalized string to its count. ...
[ "Initialize an empty dictionary for counts.", "Iterate over each label string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_upper_13(labels): counts = {} for label in labels: cleaned = label.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'name', filters to keep only those where 'priority' is <= 28, sorts the kept records by 'priority' in ascending order, and returns a list of the 'name' values in that sorted order. Do not mutate the input list.
[ "Filter the list to keep records with priority <= 28.", "Sort the filtered list by priority in ascending order.", "Extract the 'name' values from the sorted list.", "Return the list of names." ]
def select_names_by_priority_28_ascending(records): kept = [row for row in records if row["priority"] <= 28] 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 keys 'label' and 'units', and sums the 'units' for each 'label', but only for entries where 'units' is at least 4. Return a dictionary mapping label names to their total units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 4, add units to the label's total.", "Return the totals dictionary." ]
def total_units_by_label_min_4(records): totals = {} for row in records: if row["units"] >= 4: 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 keys 'label' and 'units', computes the average units per label across all entries, and returns a dictionary mapping label names to their average units, but only for labels whose average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per label, one for count per label.", "Iterate over each record: add units to total and increment count for that label.", "Compute average for each label as total divided by count.", "Return a dictionary of labels with average >= 14." ]
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 lists of integers, compares each pair of corresponding values using a margin of 100, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value exceeds the second by more than 100, 'second_ahead' for pairs where the second exceeds the fi...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over pairs using zip: compute difference left - right.", "If left - right > 100, increment 'first_ahead'; else if right - left > 100, increment 'second_ahead'; else increment 'within_margin'.", "Return the d...
def compare_pairs_with_margin_100_1(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 100: counts["first_ahead"] += 1 elif right - left > 100: counts["second_ahead"] += 1 els...
task_code
Write a Python function that takes a nested list of integers (list of rows), and for each row, keeps only integers that are at least 3 and multiplies each retained integer by 12, preserving the row order and structure. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list: iterate over values, keep those >= 3, multiply each by 12.", "Append the transformed row to the result.", "Return the result." ]
def transform_rows_0_12_3(rows): return [[value * 12 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 'label' and 'values' (a list of integers), and returns a list of 'label' values for those records where the sum of the integers in 'values' exceeds 75, preserving the original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record: compute sum of its 'values' list.", "If the sum > 75, append the 'label' value to the result.", "Return the result list." ]
def labels_over_total_75(records): return [row["label"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 25. 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 >= 25, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 complete string to uppercase, then counts how many times each normalized string appears, but only for those whose length is at least 13. Return a dictionary mapping each such normalized string to its count....
[ "Initialize an empty dictionary for counts.", "Iterate over each status string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_upper_13(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'identifier', filters to keep only those where 'priority' is <= 28, sorts the kept records by 'priority' in ascending order, and returns a list of the 'identifier' values in that sorted order. Do not mutate the input list.
[ "Filter the list to keep records with priority <= 28.", "Sort the filtered list by priority in ascending order.", "Extract the 'identifier' values from the sorted list.", "Return the list of identifiers." ]
def select_identifiers_by_priority_28_ascending(records): kept = [row for row in records if row["priority"] <= 28] 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 keys 'status' and 'units', and sums the 'units' for each 'status', but only for entries where 'units' is at least 4. Return a dictionary mapping status names to their total units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 4, add units to the status's total.", "Return the totals dictionary." ]
def total_units_by_status_min_4(records): totals = {} for row in records: if row["units"] >= 4: 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 keys 'status' and 'units', computes the average units per status across all entries, and returns a dictionary mapping status names to their average units, but only for statuses whose average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per status, one for count per status.", "Iterate over each record: add units to total and increment count for that status.", "Compute average for each status as total divided by count.", "Return a dictionary of statuses with average >= 14." ]
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 lists of integers, compares each pair of corresponding values using a margin of 0, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value exceeds the second by more than 0, 'second_ahead' for pairs where the second exceeds the first ...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over pairs using zip: compute difference left - right.", "If left - right > 0, increment 'first_ahead'; else if right - left > 0, increment 'second_ahead'; else increment 'within_margin'.", "Return the dicti...
def compare_pairs_with_margin_0_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 0: counts["first_ahead"] += 1 elif right - left > 0: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers (list of rows), and for each row, keeps only integers that are greater than 3, preserving the row order and structure. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list containing only values > 3.", "Append the filtered row to the result.", "Return the result." ]
def transform_rows_1_12_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, each with keys 'status' and 'values' (a list of integers), and returns a list of 'status' values for those records where the sum of the integers in 'values' exceeds 75, preserving the original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record: compute sum of its 'values' list.", "If the sum > 75, append the 'status' value to the result.", "Return the result list." ]
def statuss_over_total_75(records): return [row["status"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 25. 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 >= 25, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_status_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 complete string to uppercase, then counts how many times each normalized string appears, but only for those whose length is at least 13. Return a dictionary mapping each such normalized string to its coun...
[ "Initialize an empty dictionary for counts.", "Iterate over each category string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_upper_13(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, each with keys 'priority' and 'label', filters to keep only those where 'priority' is <= 28, sorts the kept records by 'priority' in ascending order, and returns a list of the 'label' values in that sorted order. Do not mutate the input list.
[ "Filter the list to keep records with priority <= 28.", "Sort the filtered list by priority in ascending order.", "Extract the 'label' values from the sorted list.", "Return the list of labels." ]
def select_labels_by_priority_28_ascending(records): kept = [row for row in records if row["priority"] <= 28] 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 keys 'category' and 'units', and sums the 'units' for each 'category', but only for entries where 'units' is at least 4. Return a dictionary mapping category names to their total units. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if units >= 4, add units to the category's total.", "Return the totals dictionary." ]
def total_units_by_category_min_4(records): totals = {} for row in records: if row["units"] >= 4: 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 keys 'category' and 'units', computes the average units per category across all entries, and returns a dictionary mapping category names to their average units, but only for categories whose average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total units per category, one for count per category.", "Iterate over each record: add units to total and increment count for that category.", "Compute average for each category as total divided by count.", "Return a dictionary of categories with average >= 14." ]
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 lists of integers, compares each pair of corresponding values using a margin of 1, and returns a dictionary with three counts: 'first_ahead' for pairs where the first value exceeds the second by more than 1, 'second_ahead' for pairs where the second exceeds the first ...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over pairs using zip: compute difference left - right.", "If left - right > 1, increment 'first_ahead'; else if right - left > 1, increment 'second_ahead'; else increment 'within_margin'.", "Return the dicti...
def compare_pairs_with_margin_1_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 1: counts["first_ahead"] += 1 elif right - left > 1: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers (list of rows), and for each row, keeps only integers that are at least 3 and adds 12 to each retained integer, preserving the row order and structure. Return the new nested list. Do not mutate the input.
[ "Initialize an empty result list.", "For each row in the input, create a new list: iterate over values, keep those >= 3, add 12 to each.", "Append the transformed row to the result.", "Return the result." ]
def transform_rows_2_12_3(rows): return [[value + 12 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 'category' and 'values' (a list of integers), and returns a list of 'category' values for those records where the sum of the integers in 'values' exceeds 75, preserving the original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each record: compute sum of its 'values' list.", "If the sum > 75, append the 'category' value to the result.", "Return the result list." ]
def categorys_over_total_75(records): return [row["category"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, sums the counts for each key across both dictionaries (treating missing keys as 0), and returns a new dictionary containing only those keys where the total is at least 25. 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 >= 25, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_category_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: result[key] = total return result
task_code
Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 13, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each topic in the input list: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_13(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' key is <= 28, sorts the kept records by 'quality' in ascending order, returns a list of the 'title' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with quality <= 28.", "Sort that 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_28_ascending(records): kept = [row for row in records if row["quality"] <= 28] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["title"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and 'units' keys, keeps only those entries where 'units' is at least 4, sums the retained 'units' grouped by 'topic', returns a new dictionary mapping each topic to its total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 4, add its units to the total for its topic.", "Return the totals dictionary." ]
def total_units_by_topic_min_4(records): totals = {} for row in records: if row["units"] >= 4: group = row["topic"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and 'units' keys, computes the average units per topic, retains only those averages that are at least 14, returns a new dictionary mapping each such topic to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total units per topic, one for count per topic.", "Iterate over each record, updating totals and counts for its topic.", "Compute the average for each topic (total / count).", "Return a dictionary of topics whose average is >= 14." ]
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 2, counts how many pairs have first value more than 2 greater than second, how many have second value more than 2 greater than first, and how many are within the margin (difference <= 2), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 2, right - left > 2, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_2_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 2: counts["first_ahead"] += 1 elif right - left > 2: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are at least 3, multiplies each retained integer by 13, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing value * 13 for each value that is >= 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_0_13_3(rows): return [[value * 13 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 'topic' and a list of integer 'values', returns a list of 'topic' values for which the sum of its 'values' list exceeds 75, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected topics.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 75, append the record's 'topic' to the result list.", "Return the result list." ]
def topics_over_total_75(records): return [row["topic"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries of topic counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 25, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 25, add to result.", "Return the result dictionary." ]
def combine_topic_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: result[key] = total return result
task_code
Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 13, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each region: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_upper_13(regions): counts = {} for region in regions: cleaned = region.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' key is <= 28, sorts the kept records by 'quality' in ascending order, returns a list of the 'name' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with quality <= 28.", "Sort that list by the 'quality' 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_quality_28_ascending(records): kept = [row for row in records if row["quality"] <= 28] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'region' and 'units' keys, keeps only those entries where 'units' is at least 4, sums the retained 'units' grouped by 'region', returns a new dictionary mapping each region to its total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 4, add its units to the total for its region.", "Return the totals dictionary." ]
def total_units_by_region_min_4(records): totals = {} for row in records: if row["units"] >= 4: group = row["region"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'region' and 'units' keys, computes the average units per region, retains only those averages that are at least 14, returns a new dictionary mapping each such region to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total units per region, one for count per region.", "Iterate over each record, updating totals and counts for its region.", "Compute the average for each region (total / count).", "Return a dictionary of regions whose average is >= 14." ]
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 3, counts how many pairs have first value more than 3 greater than second, how many have second value more than 3 greater than first, and how many are within the margin (difference <= 3), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 3, right - left > 3, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_3_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 3: counts["first_ahead"] += 1 elif right - left > 3: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are greater than 3, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing only values that are > 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_1_13_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 each with 'region' and a list of integer 'values', returns a list of 'region' values for which the sum of its 'values' list exceeds 75, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected regions.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 75, append the record's 'region' to the result list.", "Return the result list." ]
def regions_over_total_75(records): return [row["region"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries of region counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 25, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 25, add to result.", "Return the result dictionary." ]
def combine_region_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 uppercase, keeps only those normalized strings whose length is at least 13, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each team: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_upper_13(teams): counts = {} for team in teams: cleaned = team.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' key is <= 28, sorts the kept records by 'quality' in ascending order, returns a list of the 'identifier' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with quality <= 28.", "Sort that list by the 'quality' 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_quality_28_ascending(records): kept = [row for row in records if row["quality"] <= 28] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'units' keys, keeps only those entries where 'units' is at least 4, sums the retained 'units' grouped by 'team', returns a new dictionary mapping each team to its total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 4, add its units to the total for its team.", "Return the totals dictionary." ]
def total_units_by_team_min_4(records): totals = {} for row in records: if row["units"] >= 4: group = row["team"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'units' keys, computes the average units per team, retains only those averages that are at least 14, returns a new dictionary mapping each such team to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total units per team, one for count per team.", "Iterate over each record, updating totals and counts for its team.", "Compute the average for each team (total / count).", "Return a dictionary of teams whose average is >= 14." ]
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 4, counts how many pairs have first value more than 4 greater than second, how many have second value more than 4 greater than first, and how many are within the margin (difference <= 4), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 4, right - left > 4, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_4_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 4: counts["first_ahead"] += 1 elif right - left > 4: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are at least 3, adds 13 to each retained integer, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing value + 13 for each value that is >= 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_2_13_3(rows): return [[value + 13 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 'team' and a list of integer 'values', returns a list of 'team' values for which the sum of its 'values' list exceeds 75, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected teams.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 75, append the record's 'team' to the result list.", "Return the result list." ]
def teams_over_total_75(records): return [row["team"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries of team counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 25, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 25, add to result.", "Return the result dictionary." ]
def combine_team_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 uppercase, keeps only those normalized strings whose length is at least 13, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each group: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 13, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_groups_upper_13(groups): counts = {} for group in groups: cleaned = group.strip().upper() if len(cleaned) >= 13: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' key is <= 28, sorts the kept records by 'quality' in ascending order, returns a list of the 'label' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with quality <= 28.", "Sort that list by the 'quality' 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_quality_28_ascending(records): kept = [row for row in records if row["quality"] <= 28] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'units' keys, keeps only those entries where 'units' is at least 4, sums the retained 'units' grouped by 'group', returns a new dictionary mapping each group to its total units, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if units >= 4, add its units to the total for its group.", "Return the totals dictionary." ]
def total_units_by_group_min_4(records): totals = {} for row in records: if row["units"] >= 4: group = row["group"] totals[group] = totals.get(group, 0) + row["units"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'units' keys, computes the average units per group, retains only those averages that are at least 14, returns a new dictionary mapping each such group to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total units per group, one for count per group.", "Iterate over each record, updating totals and counts for its group.", "Compute the average for each group (total / count).", "Return a dictionary of groups whose average is >= 14." ]
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 5, counts how many pairs have first value more than 5 greater than second, how many have second value more than 5 greater than first, and how many are within the margin (difference <= 5), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 5, right - left > 5, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_5_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 5: counts["first_ahead"] += 1 elif right - left > 5: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are at least 3, multiplies each retained integer by 14, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing value * 14 for each value that is >= 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_0_14_3(rows): return [[value * 14 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 'group' and a list of integer 'values', returns a list of 'group' values for which the sum of its 'values' list exceeds 75, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected groups.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 75, append the record's 'group' to the result list.", "Return the result list." ]
def groups_over_total_75(records): return [row["group"] for row in records if sum(row["values"]) > 75]
task_code
Write a Python function that takes two dictionaries of group counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 25, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 25, add to result.", "Return the result dictionary." ]
def combine_group_counts_min_25(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 25: 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 entire string to lowercase, keeps only those normalized strings whose length is at least 14, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each tag: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 14, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_lower_14(tags): counts = {} for tag in tags: cleaned = tag.strip().lower() if len(cleaned) >= 14: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' key is <= 28, sorts the kept records by 'rank' in ascending order, returns a list of the 'title' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with rank <= 28.", "Sort that list by the 'rank' 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_rank_28_ascending(records): kept = [row for row in records if row["rank"] <= 28] kept = sorted(kept, key=lambda row: row["rank"], reverse=False) return [row["title"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'points' keys, keeps only those entries where 'points' is at least 4, sums the retained 'points' grouped by 'tag', returns a new dictionary mapping each tag to its total points, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 4, add its points to the total for its tag.", "Return the totals dictionary." ]
def total_points_by_tag_min_4(records): totals = {} for row in records: if row["points"] >= 4: group = row["tag"] totals[group] = totals.get(group, 0) + row["points"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'points' keys, computes the average points per tag, retains only those averages that are at least 14, returns a new dictionary mapping each such tag to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total points per tag, one for count per tag.", "Iterate over each record, updating totals and counts for its tag.", "Compute the average for each tag (total / count).", "Return a dictionary of tags whose average is >= 14." ]
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 6, counts how many pairs have first value more than 6 greater than second, how many have second value more than 6 greater than first, and how many are within the margin (difference <= 6), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 6, right - left > 6, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_6_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 6: counts["first_ahead"] += 1 elif right - left > 6: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are greater than 3, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing only values that are > 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_1_14_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 each with 'tag' and a list of integer 'values', returns a list of 'tag' values for which the sum of its 'values' list exceeds 76, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected tags.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 76, append the record's 'tag' to the result list.", "Return the result list." ]
def tags_over_total_76(records): return [row["tag"] for row in records if sum(row["values"]) > 76]
task_code
Write a Python function that takes two dictionaries of tag counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 26, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 26, add to result.", "Return the result dictionary." ]
def combine_tag_counts_min_26(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 26: 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 entire string to lowercase, keeps only those normalized strings whose length is at least 14, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list.
[ "Initialize an empty dictionary for counts.", "Iterate over each label: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 14, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_lower_14(labels): counts = {} for label in labels: cleaned = label.strip().lower() if len(cleaned) >= 14: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' key is <= 28, sorts the kept records by 'rank' in ascending order, returns a list of the 'name' values from the sorted records, and does not mutate the input list.
[ "Create a new list containing only records with rank <= 28.", "Sort that list by the 'rank' 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_rank_28_ascending(records): kept = [row for row in records if row["rank"] <= 28] kept = sorted(kept, key=lambda row: row["rank"], reverse=False) return [row["name"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'points' keys, keeps only those entries where 'points' is at least 4, sums the retained 'points' grouped by 'label', returns a new dictionary mapping each label to its total points, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record; if points >= 4, add its points to the total for its label.", "Return the totals dictionary." ]
def total_points_by_label_min_4(records): totals = {} for row in records: if row["points"] >= 4: 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 each with 'label' and 'points' keys, computes the average points per label, retains only those averages that are at least 14, returns a new dictionary mapping each such label to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total points per label, one for count per label.", "Iterate over each record, updating totals and counts for its label.", "Compute the average for each label (total / count).", "Return a dictionary of labels whose average is >= 14." ]
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 7, counts how many pairs have first value more than 7 greater than second, how many have second value more than 7 greater than first, and how many are within the margin (difference <= 7), returns a dictiona...
[ "Initialize a counts dictionary with three keys set to 0.", "Iterate over paired elements from both lists using zip.", "For each pair, compare left - right > 7, right - left > 7, else within_margin, and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_7_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 7: counts["first_ahead"] += 1 elif right - left > 7: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains within each inner list only those integers that are at least 3, adds 14 to each retained integer, preserves the order of rows and elements, returns a new nested list, and does not mutate the input.
[ "Create a new empty list for the result.", "For each inner list in the input, create a new list containing value + 14 for each value that is >= 3.", "Append that new list to the result.", "Return the result." ]
def transform_rows_2_14_3(rows): return [[value + 14 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 'label' and a list of integer 'values', returns a list of 'label' values for which the sum of its 'values' list exceeds 76, preserving the original order, and does not mutate the input list.
[ "Create an empty list for selected labels.", "Iterate over each record; compute the sum of its 'values' list.", "If the sum > 76, append the record's 'label' to the result list.", "Return the result list." ]
def labels_over_total_76(records): return [row["label"] for row in records if sum(row["values"]) > 76]
task_code
Write a Python function that takes two dictionaries of label counts, sums the values over the union of keys (treating missing keys as 0), retains only those keys where the total is at least 26, returns a new dictionary, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 26, add to result.", "Return the result dictionary." ]
def combine_label_counts_min_26(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 26: 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 to lowercase, then counts how many times each normalized string appears, but only includes those with length at least 14. Return a dictionary mapping each such normalized string to its count. Do not mutate ...
[ "Initialize an empty dictionary for counts.", "Iterate over each status string: strip whitespace and convert to lowercase.", "If the cleaned string has length >= 14, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_lower_14(statuss): counts = {} for status in statuss: cleaned = status.strip().lower() if len(cleaned) >= 14: 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', and returns a list of identifier values from those dictionaries where rank is <= 28, sorted by rank in ascending order. Do not mutate the input list.
[ "Filter the list to keep only dictionaries with rank <= 28.", "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_28_ascending(records): kept = [row for row in records if row["rank"] <= 28] 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', and returns a dictionary mapping each status to the sum of its points, but only including entries where points is at least 4. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each dictionary: if points >= 4, add points to the total for its status.", "Return the totals dictionary." ]
def total_points_by_status_min_4(records): totals = {} for row in records: if row["points"] >= 4: 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', and returns a dictionary mapping each status to its average points, but only including statuses where the average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total points per status, one for count per status.", "Iterate over each dictionary: add points to the total and increment the count for its status.", "Compute the average for each status by dividing total by count.", "Return a dictionary of statuses whose average >= 14." ...
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...
task_code
Write a Python function that takes two equal-length lists of integers and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin', counting how many pairs (from zipping the lists) have first minus second > 8, second minus first > 8, or neither (within margin). Do not mutate the input lists.
[ "Initialize a dictionary with counts set to 0 for the three categories.", "Iterate over pairs from zipping the two lists.", "For each pair, compare the difference: if first - second > 8, increment 'first_ahead'; elif second - first > 8, increment 'second_ahead'; else increment 'within_margin'.", "Return the d...
def compare_pairs_with_margin_8_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 8: counts["first_ahead"] += 1 elif right - left > 8: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only the integers that are >= 3, each multiplied by 15, preserving the order of rows and within rows. Do not mutate the input.
[ "Create a new outer list.", "For each inner list, create a new inner list containing value * 15 for each value that is >= 3.", "Append each new inner list to the outer list.", "Return the new nested list." ]
def transform_rows_0_15_3(rows): return [[value * 15 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 'status' and 'values' (a list of integers), and returns a list of 'status' values from those dictionaries where the sum of the integers in 'values' is greater than 76, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each dictionary: compute the sum of its 'values' list.", "If the sum > 76, append the 'status' to the result list.", "Return the result list." ]
def statuss_over_total_76(records): return [row["status"] for row in records if sum(row["values"]) > 76]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts and returns a new dictionary containing keys that appear in either input, with the sum of their counts from both inputs (treating missing keys as 0), but only including keys where the total is at least 26. Do not mutate the input diction...
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 26, add the key and total to the result dictionary, then return it." ]
def combine_status_counts_min_26(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 26: 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 to lowercase, then counts how many times each normalized string appears, but only includes those with length at least 14. Return a dictionary mapping each such normalized string to its count. Do not mutat...
[ "Initialize an empty dictionary for counts.", "Iterate over each category string: strip whitespace and convert to lowercase.", "If the cleaned string has length >= 14, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_lower_14(categorys): counts = {} for category in categorys: cleaned = category.strip().lower() if len(cleaned) >= 14: 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', and returns a list of label values from those dictionaries where rank is <= 28, sorted by rank in ascending order. Do not mutate the input list.
[ "Filter the list to keep only dictionaries with rank <= 28.", "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_28_ascending(records): kept = [row for row in records if row["rank"] <= 28] 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', and returns a dictionary mapping each category to the sum of its points, but only including entries where points is at least 4. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each dictionary: if points >= 4, add points to the total for its category.", "Return the totals dictionary." ]
def total_points_by_category_min_4(records): totals = {} for row in records: if row["points"] >= 4: 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', and returns a dictionary mapping each category to its average points, but only including categories where the average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total points per category, one for count per category.", "Iterate over each dictionary: add points to the total and increment the count for its category.", "Compute the average for each category by dividing total by count.", "Return a dictionary of categories whose averag...
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 and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin', counting how many pairs (from zipping the lists) have first minus second > 9, second minus first > 9, or neither (within margin). Do not mutate the input lists.
[ "Initialize a dictionary with counts set to 0 for the three categories.", "Iterate over pairs from zipping the two lists.", "For each pair, compare the difference: if first - second > 9, increment 'first_ahead'; elif second - first > 9, increment 'second_ahead'; else increment 'within_margin'.", "Return the d...
def compare_pairs_with_margin_9_2(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 9: counts["first_ahead"] += 1 elif right - left > 9: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers and returns a new nested list where each inner list contains only the integers that are greater than 3, preserving the order of rows and within rows. Do not mutate the input.
[ "Create a new outer list.", "For each inner list, create a new inner list containing each value that is > 3.", "Append each new inner list to the outer list.", "Return the new nested list." ]
def transform_rows_1_15_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, each with keys 'category' and 'values' (a list of integers), and returns a list of 'category' values from those dictionaries where the sum of the integers in 'values' is greater than 76, preserving original order. Do not mutate the input list.
[ "Initialize an empty result list.", "Iterate over each dictionary: compute the sum of its 'values' list.", "If the sum > 76, append the 'category' to the result list.", "Return the result list." ]
def categorys_over_total_76(records): return [row["category"] for row in records if sum(row["values"]) > 76]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts and returns a new dictionary containing keys that appear in either input, with the sum of their counts from both inputs (treating missing keys as 0), but only including keys where the total is at least 26. Do not mutate the input diction...
[ "Create a set of all keys from both dictionaries.", "Initialize an empty result dictionary.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 26, add the key and total to the result dictionary, then return it." ]
def combine_category_counts_min_26(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 26: 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 to lowercase, then counts how many times each normalized string appears, but only includes those with length at least 14. Return a dictionary mapping each such normalized string to its count. Do not mutate t...
[ "Initialize an empty dictionary for counts.", "Iterate over each topic string: strip whitespace and convert to lowercase.", "If the cleaned string has length >= 14, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_lower_14(topics): counts = {} for topic in topics: cleaned = topic.strip().lower() if len(cleaned) >= 14: 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', and returns a list of title values from those dictionaries where weight is <= 28, sorted by weight in ascending order. Do not mutate the input list.
[ "Filter the list to keep only dictionaries with weight <= 28.", "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_28_ascending(records): kept = [row for row in records if row["weight"] <= 28] 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', and returns a dictionary mapping each topic to the sum of its points, but only including entries where points is at least 4. Do not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each dictionary: if points >= 4, add points to the total for its topic.", "Return the totals dictionary." ]
def total_points_by_topic_min_4(records): totals = {} for row in records: if row["points"] >= 4: 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', and returns a dictionary mapping each topic to its average points, but only including topics where the average is at least 14. Do not mutate the input list.
[ "Initialize two dictionaries: one for total points per topic, one for count per topic.", "Iterate over each dictionary: add points to the total and increment the count for its topic.", "Compute the average for each topic by dividing total by count.", "Return a dictionary of topics whose average >= 14." ]
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[...