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 37, counts how many pairs have the first value more than 37 ahead of the second, how many have the second more than 37 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_37(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 37: counts["first_ahead"] += 1 elif right - left > 37: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are > 0, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 0.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_14_0(rows): return [[value for value in row if value > 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'region' and a list of integer 'values', returns a list of 'region' values for which the sum of its 'values' list exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'region' to the result.", "Return the result list." ]
def regions_over_total_54(records): return [row["region"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (using 0 for missing keys), keeps only those sums that are >= 4, returns a new dictionary with those key-sum pairs, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_region_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of team strings, strips leading/trailing whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to it...
[ "Initialize an empty dictionary for counts.", "Iterate over each team string: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_lower_3(teams): counts = {} for team in teams: cleaned = team.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' value is <= 21, sorts the kept records by 'quality' in ascending order, returns a list of the 'identifier' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with quality <= 21.", "Sort the filtered list by quality in ascending order.", "Extract the 'identifier' values from the sorted list.", "Return the list of identifiers." ]
def select_identifiers_by_quality_21_ascending(records): kept = [row for row in records if row["quality"] <= 21] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["identifier"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'sales' keys, keeps only entries where sales is >= 0, sums the sales values grouped by team, returns a new dictionary mapping each team to its total sales, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if sales >= 0, add sales to the total for its team.", "Return the totals dictionary." ]
def total_sales_by_team_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["team"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'sales' keys, computes the average sales per team, keeps only those averages that are at least 10, returns a dictionary mapping each such team to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total sales per team, one for count per team.", "Iterate over each record, updating totals and counts for its team.", "Compute average for each team as total / count.", "Return a dictionary of teams whose average >= 10." ]
def qualifying_sales_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["sales"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 38, counts how many pairs have the first value more than 38 ahead of the second, how many have the second more than 38 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_38(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 38: counts["first_ahead"] += 1 elif right - left > 38: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are >= 0, adds 14 to each retained integer, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values that are >= 0, each increased by 14.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_14_0(rows): return [[value + 14 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'team' and a list of integer 'values', returns a list of 'team' values for which the sum of its 'values' list exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'team' to the result.", "Return the result list." ]
def teams_over_total_54(records): return [row["team"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (using 0 for missing keys), keeps only those sums that are >= 4, returns a new dictionary with those key-sum pairs, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_team_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of group strings, strips leading/trailing whitespace and converts each entire string to lowercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to i...
[ "Initialize an empty dictionary for counts.", "Iterate over each group string: strip whitespace and convert to lowercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_groups_lower_3(groups): counts = {} for group in groups: cleaned = group.strip().lower() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'quality' value is <= 21, sorts the kept records by 'quality' in ascending order, returns a list of the 'label' values from the sorted records, and does not mutate the input list.
[ "Filter the list to keep records with quality <= 21.", "Sort the filtered list by quality in ascending order.", "Extract the 'label' values from the sorted list.", "Return the list of labels." ]
def select_labels_by_quality_21_ascending(records): kept = [row for row in records if row["quality"] <= 21] kept = sorted(kept, key=lambda row: row["quality"], reverse=False) return [row["label"] for row in kept]
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'sales' keys, keeps only entries where sales is >= 0, sums the sales values grouped by group, returns a new dictionary mapping each group to its total sales, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if sales >= 0, add sales to the total for its group.", "Return the totals dictionary." ]
def total_sales_by_group_min_0(records): totals = {} for row in records: if row["sales"] >= 0: group = row["group"] totals[group] = totals.get(group, 0) + row["sales"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'sales' keys, computes the average sales per group, keeps only those averages that are at least 10, returns a dictionary mapping each such group to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total sales per group, one for count per group.", "Iterate over each record, updating totals and counts for its group.", "Compute average for each group as total / count.", "Return a dictionary of groups whose average >= 10." ]
def qualifying_sales_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] totals[group] = totals.get(group, 0) + row["sales"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length lists of integers, compares each pair of corresponding values using a margin of 39, counts how many pairs have the first value more than 39 ahead of the second, how many have the second more than 39 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_39(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 39: counts["first_ahead"] += 1 elif right - left > 39: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are >= 0, multiplies each retained integer by 15, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values that are >= 0, each multiplied by 15.", "Append the new list to the result.", "Return the result." ]
def transform_rows_0_15_0(rows): return [[value * 15 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'group' and a list of integer 'values', returns a list of 'group' values for which the sum of its 'values' list exceeds 54, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 54, append the 'group' to the result.", "Return the result list." ]
def groups_over_total_54(records): return [row["group"] for row in records if sum(row["values"]) > 54]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (using 0 for missing keys), keeps only those sums that are >= 4, returns a new dictionary with those key-sum pairs, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 4, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_group_counts_min_4(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 4: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to its...
[ "Initialize an empty dictionary for counts.", "Iterate over each tag string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_upper_3(tags): counts = {} for tag in tags: cleaned = tag.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' value is <= 21, 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.
[ "Filter the list to keep records with rank <= 21.", "Sort the filtered list by rank in ascending order.", "Extract the 'title' values from the sorted list.", "Return the list of titles." ]
def select_titles_by_rank_21_ascending(records): kept = [row for row in records if row["rank"] <= 21] 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 'items' keys, keeps only entries where items is >= 0, sums the items values grouped by tag, returns a new dictionary mapping each tag to its total items, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if items >= 0, add items to the total for its tag.", "Return the totals dictionary." ]
def total_items_by_tag_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["tag"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and 'items' keys, computes the average items per tag, keeps only those averages that are at least 10, returns a dictionary mapping each such tag to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total items per tag, one for count per tag.", "Iterate over each record, updating totals and counts for its tag.", "Compute average for each tag as total / count.", "Return a dictionary of tags whose average >= 10." ]
def qualifying_items_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["items"] 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 40, counts how many pairs have the first value more than 40 ahead of the second, how many have the second more than 40 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_40(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 40: counts["first_ahead"] += 1 elif right - left > 40: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are > 0, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 0.", "Append the new list to the result.", "Return the result." ]
def transform_rows_1_15_0(rows): return [[value for value in row if value > 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'tag' and a list of integer 'values', returns a list of 'tag' values for which the sum of its 'values' list exceeds 55, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 55, append the 'tag' to the result.", "Return the result list." ]
def tags_over_total_55(records): return [row["tag"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (using 0 for missing keys), keeps only those sums that are >= 5, returns a new dictionary with those key-sum pairs, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 5, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_tag_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: 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 uppercase, keeps only those normalized strings whose length is at least 3, counts how many times each such normalized string appears, returns a dictionary mapping each normalized string to i...
[ "Initialize an empty dictionary for counts.", "Iterate over each label string: strip whitespace and convert to uppercase.", "If the cleaned string length is >= 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_upper_3(labels): counts = {} for label in labels: cleaned = label.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters to keep only those where the 'rank' value is <= 21, 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.
[ "Filter the list to keep records with rank <= 21.", "Sort the filtered list by rank in ascending order.", "Extract the 'name' values from the sorted list.", "Return the list of names." ]
def select_names_by_rank_21_ascending(records): kept = [row for row in records if row["rank"] <= 21] 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 'items' keys, keeps only entries where items is >= 0, sums the items values grouped by label, returns a new dictionary mapping each label to its total items, and does not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Iterate over each record: if items >= 0, add items to the total for its label.", "Return the totals dictionary." ]
def total_items_by_label_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["label"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'label' and 'items' keys, computes the average items per label, keeps only those averages that are at least 10, returns a dictionary mapping each such label to its average, and does not mutate the input list.
[ "Initialize two dictionaries: one for total items per label, one for count per label.", "Iterate over each record, updating totals and counts for its label.", "Compute average for each label as total / count.", "Return a dictionary of labels whose average >= 10." ]
def qualifying_items_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["items"] 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 41, counts how many pairs have the first value more than 41 ahead of the second, how many have the second more than 41 ahead of the first, and how many are within that margin (i.e., neithe...
[ "Initialize a dictionary with three counters set to 0.", "Iterate over paired elements using zip.", "For each pair, determine which category it falls into and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_41(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 41: counts["first_ahead"] += 1 elif right - left > 41: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, for each inner list retains only integers that are >= 0, adds 15 to each retained integer, returns a new nested list preserving the structure and order of rows, and does not mutate the input.
[ "Initialize an empty result list.", "For each inner list, create a new list of values that are >= 0, each increased by 15.", "Append the new list to the result.", "Return the result." ]
def transform_rows_2_15_0(rows): return [[value + 15 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'label' and a list of integer 'values', returns a list of 'label' values for which the sum of its 'values' list exceeds 55, preserving original order, and does not mutate the input.
[ "Initialize an empty result list.", "Iterate over each record: compute the sum of its 'values' list.", "If the sum > 55, append the 'label' to the result.", "Return the result list." ]
def labels_over_total_55(records): return [row["label"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (using 0 for missing keys), keeps only those sums that are >= 5, returns a new dictionary with those key-sum pairs, and does not mutate the input dictionaries.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0).", "If total >= 5, add the key and total to the result dictionary.", "Return the result dictionary." ]
def combine_label_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: result[key] = total return result
task_code
Write a Python function that takes a list of status strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input ...
[ "Initialize an empty dictionary for counts.", "Loop through each status string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_statuss_upper_3(statuss): counts = {} for status in statuss: cleaned = status.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'rank' value is <= 21, sorts the kept records by 'rank' in ascending order, and returns a list of the 'identifier' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with rank <= 21.", "Sort the filtered list by rank in ascending order.", "Extract and return the 'identifier' values from the sorted records." ]
def select_identifiers_by_rank_21_ascending(records): kept = [row for row in records if row["rank"] <= 21] 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 'status' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'status', and returns a new dictionary mapping each status to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its status.", "Return the totals dictionary." ]
def total_items_by_status_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["status"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'status' and 'items', computes the average items per status (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each status to its qualifying average. The function must not mutate the input ...
[ "Initialize two dictionaries: one for totals and one for counts per status.", "Loop through each record, updating totals and counts for its status.", "Compute average for each status; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_status(records): totals = {} counts = {} for row in records: group = row["status"] totals[group] = totals.get(group, 0) + row["items"] 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 (one from each list at the same index) using a margin of 42, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 42, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 42 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_42(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 42: counts["first_ahead"] += 1 elif right - left > 42: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 0 within each inner list, multiplies each retained integer by 16, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value * 16 for each value >= 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_0_16_0(rows): return [[value * 16 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'status' and a list of integer 'values', returns a list of 'status' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'status' to the result.", "Return the result list." ]
def statuss_over_total_55(records): return [row["status"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping statuses to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the inpu...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_status_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: result[key] = total return result
task_code
Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each entire string to uppercase, keeps only those normalized strings whose length is at least 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the inpu...
[ "Initialize an empty dictionary for counts.", "Loop through each category string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_categorys_upper_3(categorys): counts = {} for category in categorys: cleaned = category.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'rank' value is <= 21, sorts the kept records by 'rank' in ascending order, and returns a list of the 'label' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with rank <= 21.", "Sort the filtered list by rank in ascending order.", "Extract and return the 'label' values from the sorted records." ]
def select_labels_by_rank_21_ascending(records): kept = [row for row in records if row["rank"] <= 21] 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 'category' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'category', and returns a new dictionary mapping each category to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its category.", "Return the totals dictionary." ]
def total_items_by_category_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["category"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'category' and 'items', computes the average items per category (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each category to its qualifying average. The function must not mutate the ...
[ "Initialize two dictionaries: one for totals and one for counts per category.", "Loop through each record, updating totals and counts for its category.", "Compute average for each category; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_category(records): totals = {} counts = {} for row in records: group = row["category"] totals[group] = totals.get(group, 0) + row["items"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / cou...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values (one from each list at the same index) using a margin of 43, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 43, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 43 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_43(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 43: counts["first_ahead"] += 1 elif right - left > 43: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are greater than 0 within each inner list, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_1_16_0(rows): return [[value for value in row if value > 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'category' and a list of integer 'values', returns a list of 'category' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'category' to the result.", "Return the result list." ]
def categorys_over_total_55(records): return [row["category"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping categories to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the in...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_category_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: 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 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input l...
[ "Initialize an empty dictionary for counts.", "Loop through each topic string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_topics_upper_3(topics): counts = {} for topic in topics: cleaned = topic.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'weight' value is <= 21, sorts the kept records by 'weight' in ascending order, and returns a list of the 'title' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with weight <= 21.", "Sort the filtered list by weight in ascending order.", "Extract and return the 'title' values from the sorted records." ]
def select_titles_by_weight_21_ascending(records): kept = [row for row in records if row["weight"] <= 21] 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 'topic' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'topic', and returns a new dictionary mapping each topic to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its topic.", "Return the totals dictionary." ]
def total_items_by_topic_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["topic"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and 'items', computes the average items per topic (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each topic to its qualifying average. The function must not mutate the input lis...
[ "Initialize two dictionaries: one for totals and one for counts per topic.", "Loop through each record, updating totals and counts for its topic.", "Compute average for each topic; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_topic(records): totals = {} counts = {} for row in records: group = row["topic"] totals[group] = totals.get(group, 0) + row["items"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values (one from each list at the same index) using a margin of 44, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 44, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 44 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_44(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 44: counts["first_ahead"] += 1 elif right - left > 44: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 0 within each inner list, adds 16 to each retained integer, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value + 16 for each value >= 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_2_16_0(rows): return [[value + 16 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'topic' and a list of integer 'values', returns a list of 'topic' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'topic' to the result.", "Return the result list." ]
def topics_over_total_55(records): return [row["topic"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping topics to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the input ...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_topic_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: 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 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input ...
[ "Initialize an empty dictionary for counts.", "Loop through each region string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_regions_upper_3(regions): counts = {} for region in regions: cleaned = region.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'weight' value is <= 21, sorts the kept records by 'weight' in ascending order, and returns a list of the 'name' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with weight <= 21.", "Sort the filtered list by weight in ascending order.", "Extract and return the 'name' values from the sorted records." ]
def select_names_by_weight_21_ascending(records): kept = [row for row in records if row["weight"] <= 21] 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 'region' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'region', and returns a new dictionary mapping each region to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its region.", "Return the totals dictionary." ]
def total_items_by_region_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["region"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'region' and 'items', computes the average items per region (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each region to its qualifying average. The function must not mutate the input ...
[ "Initialize two dictionaries: one for totals and one for counts per region.", "Loop through each record, updating totals and counts for its region.", "Compute average for each region; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_region(records): totals = {} counts = {} for row in records: group = row["region"] totals[group] = totals.get(group, 0) + row["items"] 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 (one from each list at the same index) using a margin of 45, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 45, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 45 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_45(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 45: counts["first_ahead"] += 1 elif right - left > 45: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 0 within each inner list, multiplies each retained integer by 17, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value * 17 for each value >= 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_0_17_0(rows): return [[value * 17 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'region' and a list of integer 'values', returns a list of 'region' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'region' to the result.", "Return the result list." ]
def regions_over_total_55(records): return [row["region"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping regions to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the input...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_region_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: 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 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input li...
[ "Initialize an empty dictionary for counts.", "Loop through each team string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_teams_upper_3(teams): counts = {} for team in teams: cleaned = team.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'weight' value is <= 21, sorts the kept records by 'weight' in ascending order, and returns a list of the 'identifier' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with weight <= 21.", "Sort the filtered list by weight in ascending order.", "Extract and return the 'identifier' values from the sorted records." ]
def select_identifiers_by_weight_21_ascending(records): kept = [row for row in records if row["weight"] <= 21] 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 'team' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'team', and returns a new dictionary mapping each team to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its team.", "Return the totals dictionary." ]
def total_items_by_team_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["team"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'team' and 'items', computes the average items per team (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each team to its qualifying average. The function must not mutate the input list.
[ "Initialize two dictionaries: one for totals and one for counts per team.", "Loop through each record, updating totals and counts for its team.", "Compute average for each team; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_team(records): totals = {} counts = {} for row in records: group = row["team"] totals[group] = totals.get(group, 0) + row["items"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values (one from each list at the same index) using a margin of 46, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 46, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 46 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_46(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 46: counts["first_ahead"] += 1 elif right - left > 46: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are greater than 0 within each inner list, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing only values > 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_1_17_0(rows): return [[value for value in row if value > 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'team' and a list of integer 'values', returns a list of 'team' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'team' to the result.", "Return the result list." ]
def teams_over_total_55(records): return [row["team"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping teams to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the input d...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_team_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: 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 3, and returns a dictionary mapping each such normalized string to its count. The function must not mutate the input l...
[ "Initialize an empty dictionary for counts.", "Loop through each group string, strip and convert to uppercase, and if the cleaned string length is at least 3, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_groups_upper_3(groups): counts = {} for group in groups: cleaned = group.strip().upper() if len(cleaned) >= 3: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, keeps only those where the 'weight' value is <= 21, sorts the kept records by 'weight' in ascending order, and returns a list of the 'label' values from the sorted records. The function must not mutate the input list.
[ "Filter the list to keep records with weight <= 21.", "Sort the filtered list by weight in ascending order.", "Extract and return the 'label' values from the sorted records." ]
def select_labels_by_weight_21_ascending(records): kept = [row for row in records if row["weight"] <= 21] 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 'group' and 'items', keeps only entries where 'items' is at least 0, sums the retained 'items' values grouped by 'group', and returns a new dictionary mapping each group to its total. The function must not mutate the input list.
[ "Initialize an empty dictionary for totals.", "Loop through each record; if items >= 0, add items to the total for its group.", "Return the totals dictionary." ]
def total_items_by_group_min_0(records): totals = {} for row in records: if row["items"] >= 0: group = row["group"] totals[group] = totals.get(group, 0) + row["items"] return totals
task_code
Write a Python function that takes a list of dictionaries each with 'group' and 'items', computes the average items per group (sum of items divided by count), keeps only those averages that are at least 10, and returns a dictionary mapping each group to its qualifying average. The function must not mutate the input lis...
[ "Initialize two dictionaries: one for totals and one for counts per group.", "Loop through each record, updating totals and counts for its group.", "Compute average for each group; if average >= 10, include in result dictionary.", "Return the result dictionary." ]
def qualifying_items_averages_by_group(records): totals = {} counts = {} for row in records: group = row["group"] totals[group] = totals.get(group, 0) + row["items"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair of values (one from each list at the same index) using a margin of 47, and returns a dictionary with three counts: 'first_ahead' when the first value exceeds the second by more than 47, 'second_ahead' when the second exceeds the first...
[ "Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' all set to 0.", "Loop through paired values using zip; for each pair, compare difference to margin 47 and increment the appropriate counter.", "Return the dictionary." ]
def compare_pairs_with_margin_47(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 47: counts["first_ahead"] += 1 elif right - left > 47: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, retains only integers that are at least 0 within each inner list, adds 17 to each retained integer, and returns a new nested list preserving the original row structure and order. The function must not mutate the input list.
[ "Initialize an empty result list.", "For each inner list, create a new list containing value + 17 for each value >= 0, preserving order.", "Append the new list to the result and return the result." ]
def transform_rows_2_17_0(rows): return [[value + 17 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries each with 'group' and a list of integer 'values', returns a list of 'group' values for those records where the sum of 'values' exceeds 55, preserving original order. The function must not mutate the input list.
[ "Initialize an empty result list.", "Loop through each record; if sum of its 'values' > 55, append its 'group' to the result.", "Return the result list." ]
def groups_over_total_55(records): return [row["group"] for row in records if sum(row["values"]) > 55]
task_code
Write a Python function that takes two dictionaries mapping groups to counts, sums the counts for each key that appears in either dictionary (treating missing keys as 0), keeps only those keys where the total is at least 5, and returns a new dictionary with those keys and totals. The function must not mutate the input ...
[ "Initialize an empty result dictionary.", "Get the union of keys from both dictionaries.", "For each key, compute total = first.get(key, 0) + second.get(key, 0); if total >= 5, store in result.", "Return the result dictionary." ]
def combine_group_counts_min_5(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 5: result[key] = total return result
task_code
Write a Python function that takes a list of tag strings, strips and lowercases each, counts only those with length at least 4, returns a dictionary of counts, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Iterate over each tag, strip whitespace and convert to lowercase.", "If the cleaned string length is at least 4, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_tags_lower_4(tags): counts = {} for tag in tags: cleaned = tag.strip().lower() if len(cleaned) >= 4: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters those with rating <= 22, sorts them by rating ascending, returns a list of their title values, and does not mutate inputs.
[ "Filter the list to keep only records where rating <= 22.", "Sort the filtered list by rating in ascending order.", "Extract the title from each sorted record into a new list.", "Return the list of titles." ]
def select_titles_by_rating_22_ascending(records): kept = [row for row in records if row["rating"] <= 22] 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 'tag' and 'hours', keeps entries where hours >= 1, sums hours per tag, returns a new dictionary, and does not mutate inputs.
[ "Initialize an empty dictionary for totals.", "Iterate over each record, check if hours >= 1.", "If so, add hours to the total for that tag.", "Return the totals dictionary." ]
def total_hours_by_tag_min_1(records): totals = {} for row in records: if row["hours"] >= 1: group = row["tag"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'tag' and 'hours', computes average hours per tag, retains averages >= 11, returns a new dictionary, and does not mutate inputs.
[ "Initialize two dictionaries for totals and counts.", "Iterate over records, accumulate total hours and count per tag.", "Compute average for each tag as total / count.", "Return a dictionary of tags with average >= 11." ]
def qualifying_hours_averages_by_tag(records): totals = {} counts = {} for row in records: group = row["tag"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 48, counts pairs where first is ahead by more than 48, second is ahead by more than 48, or within margin, returns a dictionary, and does not mutate inputs.
[ "Initialize counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over paired elements using zip.", "For each pair, compare the difference to 48 and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_48(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 48: counts["first_ahead"] += 1 elif right - left > 48: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, multiplies each kept integer by 18, returns a new nested list, and does not mutate inputs.
[ "Initialize an empty result list.", "For each row, create a new list of values that are >= 0, each multiplied by 18.", "Append the transformed row to the result.", "Return the result." ]
def transform_rows_0_18_0(rows): return [[value * 18 for value in row if value >= 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'tag' and 'values' (list of ints), returns the 'tag' values where sum of 'values' > 56, preserving original order, and does not mutate inputs.
[ "Initialize an empty result list.", "Iterate over records, compute sum of the 'values' list.", "If sum > 56, append the 'tag' to the result.", "Return the result list." ]
def tags_over_total_56(records): return [row["tag"] for row in records if sum(row["values"]) > 56]
task_code
Write a Python function that takes two dictionaries of tag counts, sums values over union of keys (missing treated as 0), retains totals >= 6, returns a new dictionary, and does not mutate inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total as sum of values from both (default 0).", "If total >= 6, add key and total to result.", "Return the result dictionary." ]
def combine_tag_counts_min_6(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 6: result[key] = total return result
task_code
Write a Python function that takes a list of label strings, strips and lowercases each, counts only those with length at least 4, returns a dictionary of counts, and does not mutate the input.
[ "Initialize an empty dictionary for counts.", "Iterate over each label, strip whitespace and convert to lowercase.", "If the cleaned string length is at least 4, increment its count in the dictionary.", "Return the dictionary." ]
def count_clean_labels_lower_4(labels): counts = {} for label in labels: cleaned = label.strip().lower() if len(cleaned) >= 4: counts[cleaned] = counts.get(cleaned, 0) + 1 return counts
task_code
Write a Python function that takes a list of dictionaries, filters those with rating <= 22, sorts them by rating ascending, returns a list of their name values, and does not mutate inputs.
[ "Filter the list to keep only records where rating <= 22.", "Sort the filtered list by rating in ascending order.", "Extract the name from each sorted record into a new list.", "Return the list of names." ]
def select_names_by_rating_22_ascending(records): kept = [row for row in records if row["rating"] <= 22] 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 'label' and 'hours', keeps entries where hours >= 1, sums hours per label, returns a new dictionary, and does not mutate inputs.
[ "Initialize an empty dictionary for totals.", "Iterate over each record, check if hours >= 1.", "If so, add hours to the total for that label.", "Return the totals dictionary." ]
def total_hours_by_label_min_1(records): totals = {} for row in records: if row["hours"] >= 1: group = row["label"] totals[group] = totals.get(group, 0) + row["hours"] return totals
task_code
Write a Python function that takes a list of dictionaries with 'label' and 'hours', computes average hours per label, retains averages >= 11, returns a new dictionary, and does not mutate inputs.
[ "Initialize two dictionaries for totals and counts.", "Iterate over records, accumulate total hours and count per label.", "Compute average for each label as total / count.", "Return a dictionary of labels with average >= 11." ]
def qualifying_hours_averages_by_label(records): totals = {} counts = {} for row in records: group = row["label"] totals[group] = totals.get(group, 0) + row["hours"] counts[group] = counts.get(group, 0) + 1 return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]...
task_code
Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 49, counts pairs where first is ahead by more than 49, second is ahead by more than 49, or within margin, returns a dictionary, and does not mutate inputs.
[ "Initialize counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.", "Iterate over paired elements using zip.", "For each pair, compare the difference to 49 and increment the appropriate counter.", "Return the counts dictionary." ]
def compare_pairs_with_margin_49(first, second): counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0} for left, right in zip(first, second): if left - right > 49: counts["first_ahead"] += 1 elif right - left > 49: counts["second_ahead"] += 1 else: ...
task_code
Write a Python function that takes a nested list of integers, keeps only integers greater than 0 in each row, returns a new nested list, and does not mutate inputs.
[ "Initialize an empty result list.", "For each row, create a new list of values that are > 0.", "Append the filtered row to the result.", "Return the result." ]
def transform_rows_1_18_0(rows): return [[value for value in row if value > 0] for row in rows]
task_code
Write a Python function that takes a list of dictionaries with 'label' and 'values' (list of ints), returns the 'label' values where sum of 'values' > 56, preserving original order, and does not mutate inputs.
[ "Initialize an empty result list.", "Iterate over records, compute sum of the 'values' list.", "If sum > 56, append the 'label' to the result.", "Return the result list." ]
def labels_over_total_56(records): return [row["label"] for row in records if sum(row["values"]) > 56]
task_code
Write a Python function that takes two dictionaries of label counts, sums values over union of keys (missing treated as 0), retains totals >= 6, returns a new dictionary, and does not mutate inputs.
[ "Create a set of all keys from both dictionaries.", "For each key, compute total as sum of values from both (default 0).", "If total >= 6, add key and total to result.", "Return the result dictionary." ]
def combine_label_counts_min_6(first, second): result = {} for key in set(first) | set(second): total = first.get(key, 0) + second.get(key, 0) if total >= 6: result[key] = total return result