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 status 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 status, 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_statuss_lower_4(statuss):
counts = {}
for status in statuss:
cleaned = status.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 identifier 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 identifier from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_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["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'hours', keeps entries where hours >= 1, sums hours per status, 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 status.",
"Return the totals dictionary."
] | def total_hours_by_status_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["status"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'hours', computes average hours per status, 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 status.",
"Compute average for each status as total / count.",
"Return a dictionary of statuses with average >= 11."
] | def qualifying_hours_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["hours"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 50, counts pairs where first is ahead by more than 50, second is ahead by more than 50, 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 50 and increment the appropriate counter.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_50(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 50:
counts["first_ahead"] += 1
elif right - left > 50:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, adds 18 to each kept integer, 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 increased by 18.",
"Append the transformed row to the result.",
"Return the result."
] | def transform_rows_2_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 'status' and 'values' (list of ints), returns the 'status' 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 'status' to the result.",
"Return the result list."
] | def statuss_over_total_56(records):
return [row["status"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries of status 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_status_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 category 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 category, 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_categorys_lower_4(categorys):
counts = {}
for category in categorys:
cleaned = category.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 label 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 label from each sorted record into a new list.",
"Return the list of labels."
] | def select_labels_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["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'hours', keeps entries where hours >= 1, sums hours per category, 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 category.",
"Return the totals dictionary."
] | def total_hours_by_category_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["category"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'hours', computes average hours per category, 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 category.",
"Compute average for each category as total / count.",
"Return a dictionary of categories with average >= 11."
] | def qualifying_hours_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
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] / cou... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 51, counts pairs where first is ahead by more than 51, second is ahead by more than 51, 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 51 and increment the appropriate counter.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_51(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 51:
counts["first_ahead"] += 1
elif right - left > 51:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, multiplies each kept integer by 19, 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 19.",
"Append the transformed row to the result.",
"Return the result."
] | def transform_rows_0_19_0(rows):
return [[value * 19 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'values' (list of ints), returns the 'category' 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 'category' to the result.",
"Return the result list."
] | def categorys_over_total_56(records):
return [row["category"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries of category 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_category_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 topic 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 topic, 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_topics_lower_4(topics):
counts = {}
for topic in topics:
cleaned = topic.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 score <= 22, sorts them by score ascending, returns a list of their title values, and does not mutate inputs. | [
"Filter the list to keep only records where score <= 22.",
"Sort the filtered list by score in ascending order.",
"Extract the title from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_score_22_ascending(records):
kept = [row for row in records if row["score"] <= 22]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'topic' and 'hours', keeps entries where hours >= 1, sums hours per topic, 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 topic.",
"Return the totals dictionary."
] | def total_hours_by_topic_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'topic' and 'hours', computes average hours per topic, 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 topic.",
"Compute average for each topic as total / count.",
"Return a dictionary of topics with average >= 11."
] | def qualifying_hours_averages_by_topic(records):
totals = {}
counts = {}
for row in records:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["hours"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 52, counts pairs where first is ahead by more than 52, second is ahead by more than 52, 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 52 and increment the appropriate counter.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_52(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 52:
counts["first_ahead"] += 1
elif right - left > 52:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, 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_19_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 'topic' and 'values' (list of ints), returns the 'topic' 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 'topic' to the result.",
"Return the result list."
] | def topics_over_total_56(records):
return [row["topic"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries of topic 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_topic_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 region 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 region, 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_regions_lower_4(regions):
counts = {}
for region in regions:
cleaned = region.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 score <= 22, sorts them by score ascending, returns a list of their name values, and does not mutate inputs. | [
"Filter the list to keep only records where score <= 22.",
"Sort the filtered list by score in ascending order.",
"Extract the name from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_score_22_ascending(records):
kept = [row for row in records if row["score"] <= 22]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'hours', keeps entries where hours >= 1, sums hours per region, 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 region.",
"Return the totals dictionary."
] | def total_hours_by_region_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["region"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'hours', computes average hours per region, 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 region.",
"Compute average for each region as total / count.",
"Return a dictionary of regions with average >= 11."
] | def qualifying_hours_averages_by_region(records):
totals = {}
counts = {}
for row in records:
group = row["region"]
totals[group] = totals.get(group, 0) + row["hours"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair with a margin of 53, counts pairs where first is ahead by more than 53, second is ahead by more than 53, 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 53 and increment the appropriate counter.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_53(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 53:
counts["first_ahead"] += 1
elif right - left > 53:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, adds 19 to each kept integer, 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 increased by 19.",
"Append the transformed row to the result.",
"Return the result."
] | def transform_rows_2_19_0(rows):
return [[value + 19 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'region' and 'values' (list of ints), returns the 'region' 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 'region' to the result.",
"Return the result list."
] | def regions_over_total_56(records):
return [row["region"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries of region 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_region_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 team strings, strips and lowercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each team string, strip and lowercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_lower_4(teams):
counts = {}
for team in teams:
cleaned = team.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 with 'score' and 'identifier' keys, keeps records where score <= 22, sorts them by score in ascending order, and returns a list of the 'identifier' values. Do not mutate the input. | [
"Filter the list to keep only records with score <= 22.",
"Sort the filtered list by score in ascending order.",
"Extract the 'identifier' values from the sorted list.",
"Return the list of identifiers."
] | def select_identifiers_by_score_22_ascending(records):
kept = [row for row in records if row["score"] <= 22]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'team' and 'hours' keys, keeps entries where hours >= 1, sums the hours by team, and returns a dictionary of team totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 1, add hours to the team's total.",
"Return the totals dictionary."
] | def total_hours_by_team_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["team"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'team' and 'hours' keys, computes the average hours per team, keeps only averages >= 11, and returns a dictionary mapping team to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total hours per team and one for counts.",
"Iterate over records, updating totals and counts for each team.",
"Compute average for each team as total divided by count.",
"Return a dictionary of teams whose average is at least 11."
] | def qualifying_hours_averages_by_team(records):
totals = {}
counts = {}
for row in records:
group = row["team"]
totals[group] = totals.get(group, 0) + row["hours"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 54, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 54, increment first_ahead; else if second minus first > 54, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_54(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 54:
counts["first_ahead"] += 1
elif right - left > 54:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, multiplies each kept integer by 20, and returns the transformed nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are >= 0, each multiplied by 20.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_0_20_0(rows):
return [[value * 20 for value in row if value >= 0] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'team' and 'values' (list of ints) keys, returns the 'team' values where the sum of 'values' > 56, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 56, append the 'team' to the result.",
"Return the result list."
] | def teams_over_total_56(records):
return [row["team"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries mapping team names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 6, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 6, store in result.",
"Return the result."
] | def combine_team_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 group strings, strips and lowercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each group string, strip and lowercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_lower_4(groups):
counts = {}
for group in groups:
cleaned = group.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 with 'score' and 'label' keys, keeps records where score <= 22, sorts them by score in ascending order, and returns a list of the 'label' values. Do not mutate the input. | [
"Filter the list to keep only records with score <= 22.",
"Sort the filtered list by score in ascending order.",
"Extract the 'label' values from the sorted list.",
"Return the list of labels."
] | def select_labels_by_score_22_ascending(records):
kept = [row for row in records if row["score"] <= 22]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'group' and 'hours' keys, keeps entries where hours >= 1, sums the hours by group, and returns a dictionary of group totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 1, add hours to the group's total.",
"Return the totals dictionary."
] | def total_hours_by_group_min_1(records):
totals = {}
for row in records:
if row["hours"] >= 1:
group = row["group"]
totals[group] = totals.get(group, 0) + row["hours"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'group' and 'hours' keys, computes the average hours per group, keeps only averages >= 11, and returns a dictionary mapping group to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total hours per group and one for counts.",
"Iterate over records, updating totals and counts for each group.",
"Compute average for each group as total divided by count.",
"Return a dictionary of groups whose average is at least 11."
] | def qualifying_hours_averages_by_group(records):
totals = {}
counts = {}
for row in records:
group = row["group"]
totals[group] = totals.get(group, 0) + row["hours"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 55, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 55, increment first_ahead; else if second minus first > 55, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_55(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 55:
counts["first_ahead"] += 1
elif right - left > 55:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers greater than 0 in each row, and returns the filtered nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are > 0.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_1_20_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 'group' and 'values' (list of ints) keys, returns the 'group' values where the sum of 'values' > 56, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 56, append the 'group' to the result.",
"Return the result list."
] | def groups_over_total_56(records):
return [row["group"] for row in records if sum(row["values"]) > 56] |
task_code | Write a Python function that takes two dictionaries mapping group names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 6, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 6, store in result.",
"Return the result."
] | def combine_group_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 tag strings, strips and uppercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag string, strip and uppercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_upper_4(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().upper()
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 with 'priority' and 'title' keys, keeps records where priority <= 22, sorts them by priority in ascending order, and returns a list of the 'title' values. Do not mutate the input. | [
"Filter the list to keep only records with priority <= 22.",
"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_22_ascending(records):
kept = [row for row in records if row["priority"] <= 22]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'tag' and 'units' keys, keeps entries where units >= 1, sums the units by tag, and returns a dictionary of tag totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if units >= 1, add units to the tag's total.",
"Return the totals dictionary."
] | def total_units_by_tag_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'tag' and 'units' keys, computes the average units per tag, keeps only averages >= 11, and returns a dictionary mapping tag to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total units per tag and one for counts.",
"Iterate over records, updating totals and counts for each tag.",
"Compute average for each tag as total divided by count.",
"Return a dictionary of tags whose average is at least 11."
] | def qualifying_units_averages_by_tag(records):
totals = {}
counts = {}
for row in records:
group = row["tag"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g] >= ... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 56, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 56, increment first_ahead; else if second minus first > 56, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_56(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 56:
counts["first_ahead"] += 1
elif right - left > 56:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only non-negative integers in each row, adds 20 to each kept integer, and returns the transformed nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are >= 0, each increased by 20.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_2_20_0(rows):
return [[value + 20 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) keys, returns the 'tag' values where the sum of 'values' > 57, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 57, append the 'tag' to the result.",
"Return the result list."
] | def tags_over_total_57(records):
return [row["tag"] for row in records if sum(row["values"]) > 57] |
task_code | Write a Python function that takes two dictionaries mapping tag names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 7, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 7, store in result.",
"Return the result."
] | def combine_tag_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips and uppercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label string, strip and uppercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_upper_4(labels):
counts = {}
for label in labels:
cleaned = label.strip().upper()
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 with 'priority' and 'name' keys, keeps records where priority <= 22, sorts them by priority in ascending order, and returns a list of the 'name' values. Do not mutate the input. | [
"Filter the list to keep only records with priority <= 22.",
"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_22_ascending(records):
kept = [row for row in records if row["priority"] <= 22]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'units' keys, keeps entries where units >= 1, sums the units by label, and returns a dictionary of label totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if units >= 1, add units to the label's total.",
"Return the totals dictionary."
] | def total_units_by_label_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["label"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'units' keys, computes the average units per label, keeps only averages >= 11, and returns a dictionary mapping label to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total units per label and one for counts.",
"Iterate over records, updating totals and counts for each label.",
"Compute average for each label as total divided by count.",
"Return a dictionary of labels whose average is at least 11."
] | def qualifying_units_averages_by_label(records):
totals = {}
counts = {}
for row in records:
group = row["label"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[g]... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 57, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 57, increment first_ahead; else if second minus first > 57, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_57(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 57:
counts["first_ahead"] += 1
elif right - left > 57:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers at least 1 in each row, multiplies each kept integer by 2, and returns the transformed nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are >= 1, each multiplied by 2.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_0_2_1(rows):
return [[value * 2 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'label' and 'values' (list of ints) keys, returns the 'label' values where the sum of 'values' > 57, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 57, append the 'label' to the result.",
"Return the result list."
] | def labels_over_total_57(records):
return [row["label"] for row in records if sum(row["values"]) > 57] |
task_code | Write a Python function that takes two dictionaries mapping label names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 7, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 7, store in result.",
"Return the result."
] | def combine_label_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of status strings, strips and uppercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each status string, strip and uppercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_upper_4(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().upper()
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 with 'priority' and 'identifier' keys, keeps records where priority <= 22, sorts them by priority in ascending order, and returns a list of the 'identifier' values. Do not mutate the input. | [
"Filter the list to keep only records with priority <= 22.",
"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_22_ascending(records):
kept = [row for row in records if row["priority"] <= 22]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'units' keys, keeps entries where units >= 1, sums the units by status, and returns a dictionary of status totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if units >= 1, add units to the status's total.",
"Return the totals dictionary."
] | def total_units_by_status_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["status"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'units' keys, computes the average units per status, keeps only averages >= 11, and returns a dictionary mapping status to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total units per status and one for counts.",
"Iterate over records, updating totals and counts for each status.",
"Compute average for each status as total divided by count.",
"Return a dictionary of statuses whose average is at least 11."
] | def qualifying_units_averages_by_status(records):
totals = {}
counts = {}
for row in records:
group = row["status"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / counts[... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 58, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 58, increment first_ahead; else if second minus first > 58, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_58(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 58:
counts["first_ahead"] += 1
elif right - left > 58:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers greater than 1 in each row, and returns the filtered nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are > 1.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_1_2_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'status' and 'values' (list of ints) keys, returns the 'status' values where the sum of 'values' > 57, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 57, append the 'status' to the result.",
"Return the result list."
] | def statuss_over_total_57(records):
return [row["status"] for row in records if sum(row["values"]) > 57] |
task_code | Write a Python function that takes two dictionaries mapping status names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 7, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 7, store in result.",
"Return the result."
] | def combine_status_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of category strings, strips and uppercases each string, keeps those with length at least 4, and returns a dictionary counting occurrences of each cleaned string. Do not mutate the input. | [
"Initialize an empty dictionary for counts.",
"Iterate over each category string, strip and uppercase it.",
"If the cleaned string length is at least 4, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_4(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
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 with 'priority' and 'label' keys, keeps records where priority <= 22, sorts them by priority in ascending order, and returns a list of the 'label' values. Do not mutate the input. | [
"Filter the list to keep only records with priority <= 22.",
"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_22_ascending(records):
kept = [row for row in records if row["priority"] <= 22]
kept = sorted(kept, key=lambda row: row["priority"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'units' keys, keeps entries where units >= 1, sums the units by category, and returns a dictionary of category totals. Do not mutate the input. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if units >= 1, add units to the category's total.",
"Return the totals dictionary."
] | def total_units_by_category_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["category"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'units' keys, computes the average units per category, keeps only averages >= 11, and returns a dictionary mapping category to average. Do not mutate the input. | [
"Initialize two dictionaries: one for total units per category and one for counts.",
"Iterate over records, updating totals and counts for each category.",
"Compute average for each category as total divided by count.",
"Return a dictionary of categories whose average is at least 11."
] | def qualifying_units_averages_by_category(records):
totals = {}
counts = {}
for row in records:
group = row["category"]
totals[group] = totals.get(group, 0) + row["units"]
counts[group] = counts.get(group, 0) + 1
return {g: totals[g] / counts[g] for g in totals if totals[g] / cou... |
task_code | Write a Python function that takes two equal-length integer lists, compares each pair using a margin of 59, and returns a dictionary with counts for 'first_ahead', 'second_ahead', and 'within_margin'. Do not mutate the inputs. | [
"Initialize counts dictionary with three keys set to zero.",
"Iterate over paired elements using zip.",
"If first minus second > 59, increment first_ahead; else if second minus first > 59, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_59(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 59:
counts["first_ahead"] += 1
elif right - left > 59:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, keeps only integers at least 1 in each row, adds 2 to each kept integer, and returns the transformed nested list preserving row order. Do not mutate the input. | [
"Initialize an empty result list.",
"For each row, create a new list of values that are >= 1, each increased by 2.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_2_2_1(rows):
return [[value + 2 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with 'category' and 'values' (list of ints) keys, returns the 'category' values where the sum of 'values' > 57, preserving original order. Do not mutate the input. | [
"Initialize an empty result list.",
"Iterate over each record; if sum of its 'values' > 57, append the 'category' to the result.",
"Return the result list."
] | def categorys_over_total_57(records):
return [row["category"] for row in records if sum(row["values"]) > 57] |
task_code | Write a Python function that takes two dictionaries mapping category names to counts, sums counts over the union of keys (missing keys treated as 0), keeps only totals >= 7, and returns a new dictionary. Do not mutate the inputs. | [
"Initialize an empty result dictionary.",
"Get the set of all keys from both dictionaries.",
"For each key, compute total as first.get(key,0) + second.get(key,0); if total >= 7, store in result.",
"Return the result."
] | def combine_category_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of topic strings, strips whitespace and converts each to uppercase, keeps only those with length at least 4, and returns a dictionary counting how many times each normalized string appears. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic: strip and convert to uppercase.",
"If the cleaned string length is >= 4, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_topics_upper_4(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().upper()
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 to keep only those where the 'quality' key is <= 22, sorts the kept records by 'quality' in ascending order, and returns a list of the 'title' values in that sorted order. The input list must not be mutated. | [
"Create a new list of records where 'quality' <= 22.",
"Sort that list by 'quality' in ascending order.",
"Extract the 'title' from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_quality_22_ascending(records):
kept = [row for row in records if row["quality"] <= 22]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'units', keeps only entries where 'units' is at least 1, and returns a new dictionary mapping each topic to the sum of its retained units. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if 'units' >= 1, add its 'units' to the total for its 'topic'.",
"Return the totals dictionary."
] | def total_units_by_topic_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["topic"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and 'units', computes the average units per topic across all entries, and returns a new dictionary mapping each topic to its average only if that average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total units per topic, one for count per topic.",
"Iterate over each record: add 'units' to the total and increment count for its 'topic'.",
"Compute the average for each topic as total divided by count.",
"Return a dictionary of topics whose average is >= 11."
] | 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 lists of integers, compares each pair of values using a margin of 60, and returns a dictionary with counts for 'first_ahead' (first minus second > 60), 'second_ahead' (second minus first > 60), and 'within_margin' (otherwise). The input lists must not be mutated. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_60(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 60:
counts["first_ahead"] += 1
elif right - left > 60:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers that are at least 1 within each inner list, multiplies each retained integer by 3, and returns a new nested list preserving the original row order. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list of values >= 1 multiplied by 3.",
"Append the transformed inner list to the result.",
"Return the result."
] | def transform_rows_0_3_1(rows):
return [[value * 3 for value in row if value >= 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing 'topic' and a list of integers under 'values', and returns a list of 'topic' values for which the sum of the 'values' list exceeds 57, preserving original order. The input must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 57, append the record's 'topic' to the result.",
"Return the result list."
] | def topics_over_total_57(records):
return [row["topic"] for row in records if sum(row["values"]) > 57] |
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), and returns a new dictionary containing only those keys where the total is at least 7. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of values from both (defaulting to 0).",
"If the sum >= 7, add the key and sum to a new dictionary.",
"Return the new dictionary."
] | def combine_topic_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of region strings, strips whitespace and converts each to uppercase, keeps only those with length at least 4, and returns a dictionary counting how many times each normalized string appears. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region: strip and convert to uppercase.",
"If the cleaned string length is >= 4, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_regions_upper_4(regions):
counts = {}
for region in regions:
cleaned = region.strip().upper()
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 to keep only those where the 'quality' key is <= 22, sorts the kept records by 'quality' in ascending order, and returns a list of the 'name' values in that sorted order. The input list must not be mutated. | [
"Create a new list of records where 'quality' <= 22.",
"Sort that list by 'quality' in ascending order.",
"Extract the 'name' from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_quality_22_ascending(records):
kept = [row for row in records if row["quality"] <= 22]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'units', keeps only entries where 'units' is at least 1, and returns a new dictionary mapping each region to the sum of its retained units. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if 'units' >= 1, add its 'units' to the total for its 'region'.",
"Return the totals dictionary."
] | def total_units_by_region_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["region"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and 'units', computes the average units per region across all entries, and returns a new dictionary mapping each region to its average only if that average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total units per region, one for count per region.",
"Iterate over each record: add 'units' to the total and increment count for its 'region'.",
"Compute the average for each region as total divided by count.",
"Return a dictionary of regions whose average is >= 11."
] | 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 lists of integers, compares each pair of values using a margin of 61, and returns a dictionary with counts for 'first_ahead' (first minus second > 61), 'second_ahead' (second minus first > 61), and 'within_margin' (otherwise). The input lists must not be mutated. | [
"Initialize a dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip.",
"For each pair, determine which category it falls into and increment the corresponding count.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_61(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 61:
counts["first_ahead"] += 1
elif right - left > 61:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers greater than 1 within each inner list, and returns a new nested list preserving the original row order. The input must not be mutated. | [
"Initialize an empty result list.",
"For each inner list, create a new list of values > 1.",
"Append the filtered inner list to the result.",
"Return the result."
] | def transform_rows_1_3_1(rows):
return [[value for value in row if value > 1] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries each containing 'region' and a list of integers under 'values', and returns a list of 'region' values for which the sum of the 'values' list exceeds 57, preserving original order. The input must not be mutated. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 57, append the record's 'region' to the result.",
"Return the result list."
] | def regions_over_total_57(records):
return [row["region"] for row in records if sum(row["values"]) > 57] |
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), and returns a new dictionary containing only those keys where the total is at least 7. The input dictionaries must not be mutated. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute the sum of values from both (defaulting to 0).",
"If the sum >= 7, add the key and sum to a new dictionary.",
"Return the new dictionary."
] | def combine_region_counts_min_7(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 7:
result[key] = total
return result |
task_code | Write a Python function that takes a list of team strings, strips whitespace and converts each to uppercase, keeps only those with length at least 4, and returns a dictionary counting how many times each normalized string appears. The input list must not be mutated. | [
"Initialize an empty dictionary for counts.",
"Iterate over each team: strip and convert to uppercase.",
"If the cleaned string length is >= 4, increment its count in the dictionary.",
"Return the counts dictionary."
] | def count_clean_teams_upper_4(teams):
counts = {}
for team in teams:
cleaned = team.strip().upper()
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 to keep only those where the 'quality' key is <= 22, sorts the kept records by 'quality' in ascending order, and returns a list of the 'identifier' values in that sorted order. The input list must not be mutated. | [
"Create a new list of records where 'quality' <= 22.",
"Sort that list by 'quality' in ascending order.",
"Extract the 'identifier' from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_quality_22_ascending(records):
kept = [row for row in records if row["quality"] <= 22]
kept = sorted(kept, key=lambda row: row["quality"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'units', keeps only entries where 'units' is at least 1, and returns a new dictionary mapping each team to the sum of its retained units. The input list must not be mutated. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record: if 'units' >= 1, add its 'units' to the total for its 'team'.",
"Return the totals dictionary."
] | def total_units_by_team_min_1(records):
totals = {}
for row in records:
if row["units"] >= 1:
group = row["team"]
totals[group] = totals.get(group, 0) + row["units"]
return totals |
task_code | Write a Python function that takes a list of dictionaries each containing 'team' and 'units', computes the average units per team across all entries, and returns a new dictionary mapping each team to its average only if that average is at least 11. The input list must not be mutated. | [
"Initialize two dictionaries: one for total units per team, one for count per team.",
"Iterate over each record: add 'units' to the total and increment count for its 'team'.",
"Compute the average for each team as total divided by count.",
"Return a dictionary of teams whose average is >= 11."
] | 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] >... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.