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 integer lists, compares each pair of values (one from each list at the same position) using a margin of 36, and returns a dictionary with keys 'first_ahead', 'second_ahead', and 'within_margin' counting how many pairs fall into each category. Do not mutate the input l... | [
"Initialize counts for first_ahead, second_ahead, within_margin to 0.",
"Iterate over paired values using zip: if left - right > 36, increment first_ahead; else if right - left > 36, increment second_ahead; else increment within_margin.",
"Return the counts dictionary."
] | def compare_pairs_with_margin_36_1(first, second):
counts = {"first_ahead": 0, "second_ahead": 0, "within_margin": 0}
for left, right in zip(first, second):
if left - right > 36:
counts["first_ahead"] += 1
elif right - left > 36:
counts["second_ahead"] += 1
else:
... |
task_code | Write a Python function that takes a nested list of integers, retains only integers >= 2 within each inner list, adds 9 to each retained integer, and returns a new nested list preserving the original row order. Do not mutate the input. | [
"For each inner list, create a new list by filtering values >= 2 and adding 9 to each.",
"Collect the transformed inner lists into a new outer list.",
"Return the new nested list."
] | def transform_rows_2_9_2(rows):
return [[value + 9 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries (each with keys 'label' and 'values', where 'values' is a list of integers), and returns a list of 'label' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'label' to the result list.",
"Return the result list."
] | def labels_over_total_67(records):
return [row["label"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping keys to integer counts, computes the sum for each key that appears in either dictionary (treating missing keys as 0), and returns a new dictionary containing only those keys whose total sum is >= 17. Do not mutate the input dictionaries. | [
"Create a set of all keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add the key and total to the result dictionary.",
"Return the result dictionary."
] | def combine_label_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to it... | [
"Initialize an empty dictionary for counts.",
"Loop over each status string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_upper_9(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'identifier'. Keep only those records where 'rank' is <= 25, then sort the kept records by 'rank' in ascending order. Return a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 25.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_rank_25_ascending(records):
kept = [row for row in records if row["rank"] <= 25]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'status'. Return a dictionary mapping each status to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its status.",
"Return the totals dictionary."
] | def total_items_by_status_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'status' and 'items'. Compute the average number of items per status (total items divided by count of records for that status). Return a dictionary mapping each status to its average, but only include statuses where the average is at least 12. Do... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its status and increment the count.",
"For each status, compute the average (total / count).",
"Return a dictionary of statuses where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 37. Count how many pairs satisfy: first value minus second value > 37 (first_ahead), second value minus first value > 37 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_37_1(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 (list of rows). For each row, keep only integers that are at least 2, and multiply each kept integer by 10. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values >= 2 and multiplying each by 10.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_0_10_2(rows):
return [[value * 10 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'status' and 'values' (a list of integers). Return a list of 'status' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'status' to the result.",
"Return the result list."
] | def statuss_over_total_67(records):
return [row["status"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping statuses to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the inp... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_status_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to ... | [
"Initialize an empty dictionary for counts.",
"Loop over each category string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_upper_9(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'rank' and 'label'. Keep only those records where 'rank' is <= 25, then sort the kept records by 'rank' in ascending order. Return a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with rank <= 25.",
"Sort the filtered list by the 'rank' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return the list of labels."
] | def select_labels_by_rank_25_ascending(records):
kept = [row for row in records if row["rank"] <= 25]
kept = sorted(kept, key=lambda row: row["rank"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'category'. Return a dictionary mapping each category to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its category.",
"Return the totals dictionary."
] | def total_items_by_category_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'category' and 'items'. Compute the average number of items per category (total items divided by count of records for that category). Return a dictionary mapping each category to its average, but only include categories where the average is at le... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its category and increment the count.",
"For each category, compute the average (total / count).",
"Return a dictionary of categories where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 38. Count how many pairs satisfy: first value minus second value > 38 (first_ahead), second value minus first value > 38 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_38_1(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 (list of rows). For each row, keep only integers that are greater than 2. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values > 2.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_1_10_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'category' and 'values' (a list of integers). Return a list of 'category' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'category' to the result.",
"Return the result list."
] | def categorys_over_total_67(records):
return [row["category"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping categories to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the i... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_category_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to its... | [
"Initialize an empty dictionary for counts.",
"Loop over each topic string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_upper_9(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'weight' and 'title'. Keep only those records where 'weight' is <= 25, then sort the kept records by 'weight' in ascending order. Return a list of the 'title' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 25.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'title' values from the sorted records into a new list.",
"Return the list of titles."
] | def select_titles_by_weight_25_ascending(records):
kept = [row for row in records if row["weight"] <= 25]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'topic'. Return a dictionary mapping each topic to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its topic.",
"Return the totals dictionary."
] | def total_items_by_topic_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'topic' and 'items'. Compute the average number of items per topic (total items divided by count of records for that topic). Return a dictionary mapping each topic to its average, but only include topics where the average is at least 12. Do not m... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its topic and increment the count.",
"For each topic, compute the average (total / count).",
"Return a dictionary of topics where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 39. Count how many pairs satisfy: first value minus second value > 39 (first_ahead), second value minus first value > 39 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_39_1(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 (list of rows). For each row, keep only integers that are at least 2, and add 10 to each kept integer. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values >= 2 and adding 10 to each.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_2_10_2(rows):
return [[value + 10 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'topic' and 'values' (a list of integers). Return a list of 'topic' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'topic' to the result.",
"Return the result list."
] | def topics_over_total_67(records):
return [row["topic"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping topics to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the input... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_topic_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to it... | [
"Initialize an empty dictionary for counts.",
"Loop over each region string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_upper_9(regions):
counts = {}
for region in regions:
cleaned = region.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'weight' and 'name'. Keep only those records where 'weight' is <= 25, then sort the kept records by 'weight' in ascending order. Return a list of the 'name' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 25.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'name' values from the sorted records into a new list.",
"Return the list of names."
] | def select_names_by_weight_25_ascending(records):
kept = [row for row in records if row["weight"] <= 25]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'region'. Return a dictionary mapping each region to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its region.",
"Return the totals dictionary."
] | def total_items_by_region_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'region' and 'items'. Compute the average number of items per region (total items divided by count of records for that region). Return a dictionary mapping each region to its average, but only include regions where the average is at least 12. Do ... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its region and increment the count.",
"For each region, compute the average (total / count).",
"Return a dictionary of regions where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 40. Count how many pairs satisfy: first value minus second value > 40 (first_ahead), second value minus first value > 40 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_40_1(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 (list of rows). For each row, keep only integers that are at least 2, and multiply each kept integer by 11. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values >= 2 and multiplying each by 11.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_0_11_2(rows):
return [[value * 11 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'region' and 'values' (a list of integers). Return a list of 'region' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'region' to the result.",
"Return the result list."
] | def regions_over_total_67(records):
return [row["region"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping regions to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the inpu... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_region_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to its ... | [
"Initialize an empty dictionary for counts.",
"Loop over each team string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_teams_upper_9(teams):
counts = {}
for team in teams:
cleaned = team.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'weight' and 'identifier'. Keep only those records where 'weight' is <= 25, then sort the kept records by 'weight' in ascending order. Return a list of the 'identifier' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 25.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'identifier' values from the sorted records into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_weight_25_ascending(records):
kept = [row for row in records if row["weight"] <= 25]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'team'. Return a dictionary mapping each team to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its team.",
"Return the totals dictionary."
] | def total_items_by_team_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'team' and 'items'. Compute the average number of items per team (total items divided by count of records for that team). Return a dictionary mapping each team to its average, but only include teams where the average is at least 12. Do not mutate... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its team and increment the count.",
"For each team, compute the average (total / count).",
"Return a dictionary of teams where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 41. Count how many pairs satisfy: first value minus second value > 41 (first_ahead), second value minus first value > 41 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_41_1(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 (list of rows). For each row, keep only integers that are greater than 2. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values > 2.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_1_11_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'team' and 'values' (a list of integers). Return a list of 'team' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'team' to the result.",
"Return the result list."
] | def teams_over_total_67(records):
return [row["team"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping teams to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the input ... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_team_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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, then counts how many times each normalized string appears, but only includes those whose length is at least 9. Return a dictionary mapping each qualifying normalized string to its... | [
"Initialize an empty dictionary for counts.",
"Loop over each group string: strip whitespace and convert to uppercase.",
"If the cleaned string length is >= 9, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_groups_upper_9(groups):
counts = {}
for group in groups:
cleaned = group.strip().upper()
if len(cleaned) >= 9:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'weight' and 'label'. Keep only those records where 'weight' is <= 25, then sort the kept records by 'weight' in ascending order. Return a list of the 'label' values from the sorted records. Do not mutate the input list. | [
"Filter the list to keep records with weight <= 25.",
"Sort the filtered list by the 'weight' key in ascending order.",
"Extract the 'label' values from the sorted records into a new list.",
"Return the list of labels."
] | def select_labels_by_weight_25_ascending(records):
kept = [row for row in records if row["weight"] <= 25]
kept = sorted(kept, key=lambda row: row["weight"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'group' and 'items'. Keep only entries where 'items' is at least 2, then sum the 'items' values grouped by 'group'. Return a dictionary mapping each group to its total items. Do not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Loop over each record: if items >= 2, add items to the total for its group.",
"Return the totals dictionary."
] | def total_items_by_group_min_2(records):
totals = {}
for row in records:
if row["items"] >= 2:
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 keys 'group' and 'items'. Compute the average number of items per group (total items divided by count of records for that group). Return a dictionary mapping each group to its average, but only include groups where the average is at least 12. Do not m... | [
"Initialize two dictionaries: one for totals, one for counts.",
"Loop over each record: add items to the total for its group and increment the count.",
"For each group, compute the average (total / count).",
"Return a dictionary of groups where the average >= 12."
] | 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 lists of integers. Compare each pair of values (one from each list at the same position) using a margin of 42. Count how many pairs satisfy: first value minus second value > 42 (first_ahead), second value minus first value > 42 (second_ahead), or neither (within_margi... | [
"Initialize a dictionary with three counters set to 0.",
"Loop over paired elements using zip.",
"For each pair, check the difference and increment the appropriate counter.",
"Return the dictionary."
] | def compare_pairs_with_margin_42_1(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 (list of rows). For each row, keep only integers that are at least 2, and add 11 to each kept integer. Return a new nested list with the same row structure and order. Do not mutate the input. | [
"Create an empty result list.",
"Loop over each row: create a new row by filtering values >= 2 and adding 11 to each.",
"Append the new row to the result.",
"Return the result."
] | def transform_rows_2_11_2(rows):
return [[value + 11 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries, each with keys 'group' and 'values' (a list of integers). Return a list of 'group' values for which the sum of the integers in 'values' exceeds 67, preserving the original order. Do not mutate the input list. | [
"Initialize an empty result list.",
"Loop over each record: compute the sum of its 'values' list.",
"If the sum > 67, append the 'group' to the result.",
"Return the result list."
] | def groups_over_total_67(records):
return [row["group"] for row in records if sum(row["values"]) > 67] |
task_code | Write a Python function that takes two dictionaries mapping groups to integer counts. For each key that appears in either dictionary, compute the sum of the counts (using 0 for missing keys). Keep only those keys where the total is at least 17. Return a new dictionary with those keys and totals. Do not mutate the input... | [
"Create a set of all keys from both dictionaries.",
"Initialize an empty result dictionary.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 17, add key: total to result. Return result."
] | def combine_group_counts_min_17(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 17:
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 complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each tag in the input list; strip and lowercase the tag.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_tags_lower_10(tags):
counts = {}
for tag in tags:
cleaned = tag.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is <= 26, sorts the kept records by 'rating' 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 rating <= 26.",
"Sort the filtered list by the 'rating' key in ascending order.",
"Extract the 'title' value from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_rating_26_ascending(records):
kept = [row for row in records if row["rating"] <= 26]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'tag' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'tag', returns a new dictionary mapping each tag to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its tag.",
"Return the totals dictionary."
] | def total_hours_by_tag_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'tag' and 'hours', computes the average hours per tag, keeps only those averages that are at least 13, returns a dictionary mapping each such tag to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per tag, one for count per tag.",
"Iterate over each record; accumulate total hours and count for its tag.",
"Compute average for each tag as total / count.",
"Return a dictionary of tags whose average >= 13."
] | 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 paired values using a margin of 43, counts how many pairs have the first value ahead by more than 43, how many have the second value ahead by more than 43, and how many are within the margin (difference <= 43), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 43, increment 'first_ahead'; else if right - left > 43, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_43_1(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 within each row only integers that are at least 2, multiplies each retained integer by 12, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values >= 2 and multiplies each by 12.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_0_12_2(rows):
return [[value * 12 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'tag' and 'values' (a list of integers), returns a list of 'tag' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'tag' to the result list.",
"Return the result list."
] | def tags_over_total_68(records):
return [row["tag"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping tags to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_tag_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
task_code | Write a Python function that takes a list of label strings, strips leading/trailing whitespace and converts each complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each label; strip and lowercase it.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_labels_lower_10(labels):
counts = {}
for label in labels:
cleaned = label.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is <= 26, sorts the kept records by 'rating' 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 rating <= 26.",
"Sort the filtered list by the 'rating' key in ascending order.",
"Extract the 'name' value from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_rating_26_ascending(records):
kept = [row for row in records if row["rating"] <= 26]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'label' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'label', returns a new dictionary mapping each label to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its label.",
"Return the totals dictionary."
] | def total_hours_by_label_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'label' and 'hours', computes the average hours per label, keeps only those averages that are at least 13, returns a dictionary mapping each such label to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per label, one for count per label.",
"Iterate over each record; accumulate total hours and count for its label.",
"Compute average for each label as total / count.",
"Return a dictionary of labels whose average >= 13."
] | 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 paired values using a margin of 44, counts how many pairs have the first value ahead by more than 44, how many have the second value ahead by more than 44, and how many are within the margin (difference <= 44), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 44, increment 'first_ahead'; else if right - left > 44, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_44_1(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, keeps within each row only integers that are greater than 2, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values > 2.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_1_12_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'label' and 'values' (a list of integers), returns a list of 'label' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'label' to the result list.",
"Return the result list."
] | def labels_over_total_68(records):
return [row["label"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping labels to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_label_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
task_code | Write a Python function that takes a list of status strings, strips leading/trailing whitespace and converts each complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each status; strip and lowercase it.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_statuss_lower_10(statuss):
counts = {}
for status in statuss:
cleaned = status.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is <= 26, sorts the kept records by 'rating' 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 rating <= 26.",
"Sort the filtered list by the 'rating' key in ascending order.",
"Extract the 'identifier' value from each sorted record into a new list.",
"Return the list of identifiers."
] | def select_identifiers_by_rating_26_ascending(records):
kept = [row for row in records if row["rating"] <= 26]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["identifier"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'status' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'status', returns a new dictionary mapping each status to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its status.",
"Return the totals dictionary."
] | def total_hours_by_status_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'status' and 'hours', computes the average hours per status, keeps only those averages that are at least 13, returns a dictionary mapping each such status to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per status, one for count per status.",
"Iterate over each record; accumulate total hours and count for its status.",
"Compute average for each status as total / count.",
"Return a dictionary of statuses whose average >= 13."
] | 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 paired values using a margin of 45, counts how many pairs have the first value ahead by more than 45, how many have the second value ahead by more than 45, and how many are within the margin (difference <= 45), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 45, increment 'first_ahead'; else if right - left > 45, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_45_1(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 within each row only integers that are at least 2, adds 12 to each retained integer, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values >= 2 and adds 12 to each.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_2_12_2(rows):
return [[value + 12 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'status' and 'values' (a list of integers), returns a list of 'status' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'status' to the result list.",
"Return the result list."
] | def statuss_over_total_68(records):
return [row["status"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping statuses to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_status_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
task_code | Write a Python function that takes a list of category strings, strips leading/trailing whitespace and converts each complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each category; strip and lowercase it.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_categorys_lower_10(categorys):
counts = {}
for category in categorys:
cleaned = category.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'rating' key is <= 26, sorts the kept records by 'rating' 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 rating <= 26.",
"Sort the filtered list by the 'rating' key in ascending order.",
"Extract the 'label' value from each sorted record into a new list.",
"Return the list of labels."
] | def select_labels_by_rating_26_ascending(records):
kept = [row for row in records if row["rating"] <= 26]
kept = sorted(kept, key=lambda row: row["rating"], reverse=False)
return [row["label"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'category' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'category', returns a new dictionary mapping each category to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its category.",
"Return the totals dictionary."
] | def total_hours_by_category_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'category' and 'hours', computes the average hours per category, keeps only those averages that are at least 13, returns a dictionary mapping each such category to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per category, one for count per category.",
"Iterate over each record; accumulate total hours and count for its category.",
"Compute average for each category as total / count.",
"Return a dictionary of categories whose average >= 13."
] | 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 paired values using a margin of 46, counts how many pairs have the first value ahead by more than 46, how many have the second value ahead by more than 46, and how many are within the margin (difference <= 46), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 46, increment 'first_ahead'; else if right - left > 46, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_46_1(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 within each row only integers that are at least 2, multiplies each retained integer by 13, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values >= 2 and multiplies each by 13.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_0_13_2(rows):
return [[value * 13 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'category' and 'values' (a list of integers), returns a list of 'category' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'category' to the result list.",
"Return the result list."
] | def categorys_over_total_68(records):
return [row["category"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping categories to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_category_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
task_code | Write a Python function that takes a list of topic strings, strips leading/trailing whitespace and converts each complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each topic; strip and lowercase it.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_topics_lower_10(topics):
counts = {}
for topic in topics:
cleaned = topic.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'score' key is <= 26, sorts the kept records by 'score' 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 score <= 26.",
"Sort the filtered list by the 'score' key in ascending order.",
"Extract the 'title' value from each sorted record into a new list.",
"Return the list of titles."
] | def select_titles_by_score_26_ascending(records):
kept = [row for row in records if row["score"] <= 26]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["title"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'topic' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'topic', returns a new dictionary mapping each topic to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its topic.",
"Return the totals dictionary."
] | def total_hours_by_topic_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'topic' and 'hours', computes the average hours per topic, keeps only those averages that are at least 13, returns a dictionary mapping each such topic to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per topic, one for count per topic.",
"Iterate over each record; accumulate total hours and count for its topic.",
"Compute average for each topic as total / count.",
"Return a dictionary of topics whose average >= 13."
] | 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 paired values using a margin of 47, counts how many pairs have the first value ahead by more than 47, how many have the second value ahead by more than 47, and how many are within the margin (difference <= 47), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 47, increment 'first_ahead'; else if right - left > 47, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_47_1(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, keeps within each row only integers that are greater than 2, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values > 2.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_1_13_2(rows):
return [[value for value in row if value > 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'topic' and 'values' (a list of integers), returns a list of 'topic' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'topic' to the result list.",
"Return the result list."
] | def topics_over_total_68(records):
return [row["topic"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping topics to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_topic_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
task_code | Write a Python function that takes a list of region strings, strips leading/trailing whitespace and converts each complete string to lowercase, keeps only normalized strings whose length is at least 10, returns a dictionary mapping each such normalized string to its count, and does not mutate the input list. | [
"Initialize an empty dictionary for counts.",
"Iterate over each region; strip and lowercase it.",
"If the cleaned string length is >= 10, increment its count in the dictionary.",
"Return the dictionary."
] | def count_clean_regions_lower_10(regions):
counts = {}
for region in regions:
cleaned = region.strip().lower()
if len(cleaned) >= 10:
counts[cleaned] = counts.get(cleaned, 0) + 1
return counts |
task_code | Write a Python function that takes a list of dictionaries, keeps only those records where the 'score' key is <= 26, sorts the kept records by 'score' 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 score <= 26.",
"Sort the filtered list by the 'score' key in ascending order.",
"Extract the 'name' value from each sorted record into a new list.",
"Return the list of names."
] | def select_names_by_score_26_ascending(records):
kept = [row for row in records if row["score"] <= 26]
kept = sorted(kept, key=lambda row: row["score"], reverse=False)
return [row["name"] for row in kept] |
task_code | Write a Python function that takes a list of dictionaries with keys 'region' and 'hours', keeps only those entries where 'hours' is at least 3, sums the retained hours grouped by 'region', returns a new dictionary mapping each region to its total hours, and does not mutate the input list. | [
"Initialize an empty dictionary for totals.",
"Iterate over each record; if hours >= 3, add hours to the total for its region.",
"Return the totals dictionary."
] | def total_hours_by_region_min_3(records):
totals = {}
for row in records:
if row["hours"] >= 3:
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 keys 'region' and 'hours', computes the average hours per region, keeps only those averages that are at least 13, returns a dictionary mapping each such region to its average, and does not mutate the input list. | [
"Initialize two dictionaries: one for total hours per region, one for count per region.",
"Iterate over each record; accumulate total hours and count for its region.",
"Compute average for each region as total / count.",
"Return a dictionary of regions whose average >= 13."
] | 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 paired values using a margin of 48, counts how many pairs have the first value ahead by more than 48, how many have the second value ahead by more than 48, and how many are within the margin (difference <= 48), returns a dictionary with keys 'f... | [
"Initialize a counts dictionary with keys 'first_ahead', 'second_ahead', 'within_margin' set to 0.",
"Iterate over paired elements using zip; compare left and right.",
"If left - right > 48, increment 'first_ahead'; else if right - left > 48, increment 'second_ahead'; else increment 'within_margin'.",
"Return... | def compare_pairs_with_margin_48_1(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, retains within each row only integers that are at least 2, adds 13 to each retained integer, preserves the row structure and order, returns a new nested list, and does not mutate the input. | [
"Initialize an empty result list.",
"For each row in the input, create a new list comprehension that filters values >= 2 and adds 13 to each.",
"Append the new row to the result list.",
"Return the result list."
] | def transform_rows_2_13_2(rows):
return [[value + 13 for value in row if value >= 2] for row in rows] |
task_code | Write a Python function that takes a list of dictionaries with keys 'region' and 'values' (a list of integers), returns a list of 'region' values for those records where the sum of the integers in 'values' exceeds 68, preserving original order, and does not mutate the input list. | [
"Initialize an empty result list.",
"Iterate over each record; compute the sum of its 'values' list.",
"If the sum > 68, append the record's 'region' to the result list.",
"Return the result list."
] | def regions_over_total_68(records):
return [row["region"] for row in records if sum(row["values"]) > 68] |
task_code | Write a Python function that takes two dictionaries mapping regions to counts, sums the counts over the union of keys (treating missing keys as 0), keeps only those keys where the total is at least 18, returns a new dictionary with those keys and totals, and does not mutate the input dictionaries. | [
"Initialize an empty result dictionary.",
"Iterate over the union of keys from both dictionaries.",
"For each key, compute total = first.get(key, 0) + second.get(key, 0).",
"If total >= 18, add key and total to result; return result."
] | def combine_region_counts_min_18(first, second):
result = {}
for key in set(first) | set(second):
total = first.get(key, 0) + second.get(key, 0)
if total >= 18:
result[key] = total
return result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.