id stringlengths 25 25 | kind stringclasses 1
value | title stringlengths 17 17 | provisional bool 1
class | output_code stringlengths 60 4.12k | input_data_sample stringlengths 3 637 | output_data_sample unknown | transformation_instruction stringlengths 54 1.91k |
|---|---|---|---|---|---|---|---|
cmsvchtev01nxg4p2tt1jheag | contributor_item | Submission 1JHEAG | false | def transform(text):
out = []
for line in text.rstrip('\n').split('\n'):
if line.startswith(' ') and out:
out[-1] = out[-1] + ' ' + line.strip()
elif line.strip():
key, _, value = line.partition(':')
out.append('{}={}'.format(key.strip(), value.strip()))
... | title: The Long
and Winding Road
artist: Someone
notes: first
second
third
| "title=The Long and Winding Road\nartist=Someone\nnotes=first second third" | Given lines of 'field: value' where a value may continue onto following lines that start with two spaces, join each continuation onto its field with a single space and return 'field=value' lines in the original order. |
cmsvg9cb901ong4p2bfgnzyyy | contributor_item | Submission GNZYYY | false | import json
def transform(text):
result = {}
for line in text.strip().split("\n"):
if ":" not in line:
continue
key, value = line.split(":", 1)
key = key.strip()
value = value.strip()
if value.lower() == "true":
typed = True
elif value.low... | name: Widget
price: 19.99
in_stock: true
quantity: 42
discontinued: false
| {
"name": "Widget",
"price": 19.99,
"in_stock": true,
"quantity": 42,
"discontinued": false
} | Parse simple 'key: value' lines into a JSON object, inferring booleans, integers, floats, and falling back to strings. |
cmsvg9cb901omg4p2mkx8toqh | contributor_item | Submission X8TOQH | false | import json
def transform(text):
result = {}
section = None
for line in text.strip().split("\n"):
line = line.strip()
if not line:
continue
if line.startswith("[") and line.endswith("]"):
section = line[1:-1]
result[section] = {}
elif "=" ... | [server]
host=localhost
port=8080
[database]
name=appdb
timeout=30
| {
"server": {
"host": "localhost",
"port": 8080
},
"database": {
"name": "appdb",
"timeout": 30
}
} | Parse an INI-style config file into a nested JSON object grouped by section, converting numeric values to integers. |
cmsvg9cb901oog4p2socjmqt6 | contributor_item | Submission CJMQT6 | false | import json
def transform(text):
lines = [l for l in text.strip("\n").split("\n") if l.strip()]
header = lines[0]
col_starts = []
for i, ch in enumerate(header):
if ch != " " and (i == 0 or header[i-1] == " "):
col_starts.append(i)
names = header.split()
rows = []
for li... | NAME AGE CITY
Alice 30 Boston
Bob 25 Denver
Carol 41 Reno
| [
{
"NAME": "Alice",
"AGE": 30,
"CITY": "Boston"
},
{
"NAME": "Bob",
"AGE": 25,
"CITY": "Denver"
},
{
"NAME": "Carol",
"AGE": 41,
"CITY": "Reno"
}
] | Convert a fixed-width column-aligned text table (header + rows) into a JSON list of objects, converting the AGE column to an integer. |
cmsvg9cb901opg4p2549fr6gj | contributor_item | Submission 9FR6GJ | false | import csv, io
def transform(text):
lines = [l for l in text.strip("\n").split("\n") if l.strip()]
rows = []
for line in lines:
fields = [f.strip('"') for f in line.split('";"')]
fields[0] = fields[0].lstrip('"')
fields[-1] = fields[-1].rstrip('"')
rows.append(fields)
ou... | "Smith; John";"42";"New York; NY"
"Doe; Jane";"31";"Austin; TX"
| "Smith; John,42,New York; NY\r\nDoe; Jane,31,Austin; TX" | Convert semicolon-quoted rows like '"Field; A";"Field2"' into standard comma-separated CSV rows, preserving embedded semicolons inside each quoted field. |
cmsvg9cb901oqg4p27yvnpiaa | contributor_item | Submission VNPIAA | false | import json
from collections import defaultdict
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
header = lines[0].split(",")
totals = defaultdict(float)
for line in lines[1:]:
parts = line.split(",")
row = dict(zip(header, parts))
revenue = int(ro... | product,qty,price
widget,3,9.99
gadget,1,19.99
widget,2,9.99
gizmo,5,4.50
gadget,2,19.99
| {
"gadget": 59.97,
"gizmo": 22.5,
"widget": 49.95
} | Compute total revenue (qty * price) per product from CSV lines with a header row, rounding each total to 2 decimal places. |
cmsvgmejh01qjg4p2gneikbhf | contributor_item | Submission EIKBHF | false | import json, re
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
result = []
for line in lines:
m = re.match(r"- \[( |x)\] (.+)", line)
done = m.group(1) == "x"
result.append({"text": m.group(2), "done": done})
return json.dumps(result) | - [ ] Buy milk
- [x] Walk dog
- [ ] Write report
- [x] Pay bills | [
{
"text": "Buy milk",
"done": false
},
{
"text": "Walk dog",
"done": true
},
{
"text": "Write report",
"done": false
},
{
"text": "Pay bills",
"done": true
}
] | Parse a Markdown todo list ('- [ ]' or '- [x]') into a JSON list of {text, done} objects. |
cmsvgmejh01q8g4p25exdfhnb | contributor_item | Submission XDFHNB | false | import json
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
result = [round(float(l) * 9 / 5 + 32, 1) for l in lines]
return json.dumps(result) | 0
20
37
100 | [
32,
68,
98.6,
212
] | Convert a list of Celsius temperature lines into a JSON list of Fahrenheit values rounded to 1 decimal. |
cmsvgmejh01q6g4p24a9tp05x | contributor_item | Submission 9TP05X | false | import json
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
header = lines[0].split(",")
rows = []
for line in lines[1:]:
values = line.split(",")
row = {}
for k, v in zip(header, values):
row[k] = int(v) if v.isdigit() else v
... | name,age
Alice,30
Bob,25
| [
{
"name": "Alice",
"age": 30
},
{
"name": "Bob",
"age": 25
}
] | Convert CSV with a header row into a JSON list of objects, converting numeric-looking values to integers. |
cmsvgmejh01q9g4p28sj42le1 | contributor_item | Submission J42LE1 | false | import json
def flatten(d, prefix=""):
items = {}
for k, v in d.items():
key = f"{prefix}.{k}" if prefix else k
if isinstance(v, dict):
items.update(flatten(v, key))
else:
items[key] = v
return items
def transform(text):
data = json.loads(text)
retur... | {"user": {"profile": {"name": "Alice", "age": 30}, "active": true}} | {
"user.profile.name": "Alice",
"user.profile.age": 30,
"user.active": true
} | Flatten a nested JSON object into a single-level JSON object with dot-notation keys. |
cmsvgmejh01qcg4p2gnj5n6jv | contributor_item | Submission J5N6JV | false | import json
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
result = []
for line in lines:
name, email = line.split(",")
result.append({"name": name.strip(), "email": email.strip().lower()})
return json.dumps(result) | Alice Smith,ALICE@Example.com
Bob Jones,BOB@test.COM | [
{
"name": "Alice Smith",
"email": "alice@example.com"
},
{
"name": "Bob Jones",
"email": "bob@test.com"
}
] | Convert 'name,email' CSV lines into a JSON list of objects with lower-cased email addresses. |
cmsvgmejh01qfg4p2f8twigje | contributor_item | Submission TWIGJE | false | import csv, io
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
header = lines[0].split(",")
out = io.StringIO()
writer = csv.writer(out)
writer.writerow(header + ["running_total"])
running = 0
for line in lines[1:]:
parts = line.split(",")
run... | item,amount
coffee,4
bagel,3
tea,2 | "item,amount,running_total\r\ncoffee,4,4\r\nbagel,3,7\r\ntea,2,9" | Add a cumulative running-total column to CSV data and return the result as a CSV string. |
cmsvgmejh01qdg4p2cd00npxn | contributor_item | Submission 00NPXN | false | import json
def transform(text):
data = json.loads(text)
merged = {}
order = []
for row in data:
rid = row["id"]
if rid not in merged:
order.append(rid)
merged[rid] = {}
merged[rid].update(row)
return json.dumps([merged[rid] for rid in order]) | [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, {"id": 1, "name": "Alice Updated", "age": 31}] | [
{
"id": 1,
"name": "Alice Updated",
"age": 31
},
{
"id": 2,
"name": "Bob"
}
] | Merge a JSON list of records by id, where later records override or add fields from earlier ones with the same id. |
cmsvgmejh01qig4p2zfh5xbjk | contributor_item | Submission H5XBJK | false | import math
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
points = [tuple(map(float, l.split(","))) for l in lines]
total = 0.0
for i in range(len(points) - 1):
x1, y1 = points[i]
x2, y2 = points[i + 1]
total += math.hypot(x2 - x1, y2 - y1)
... | 0,0
3,4
3,0 | 9 | Given a list of x,y coordinate lines describing a path in order, compute the total Euclidean path distance rounded to 2 decimals. |
cmsvgmejh01qkg4p2uzc3czq9 | contributor_item | Submission C3CZQ9 | false | import json
def to_camel(s):
parts = s.split("_")
return parts[0] + "".join(p.capitalize() for p in parts[1:])
def transform(text):
data = json.loads(text)
return json.dumps({to_camel(k): v for k, v in data.items()}) | {"first_name": "Alice", "last_name": "Smith", "home_address": "123 Main St"} | {
"firstName": "Alice",
"lastName": "Smith",
"homeAddress": "123 Main St"
} | Convert snake_case keys in a flat JSON object to camelCase keys. |
cmsvgmejh01qng4p2fxpx86qd | contributor_item | Submission PX86QD | false | import re, json
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
result = []
for line in lines:
h = re.search(r"(\d+)h", line)
m = re.search(r"(\d+)m", line)
total = (int(h.group(1)) * 60 if h else 0) + (int(m.group(1)) if m else 0)
result.appe... | 1h30m
45m
2h
90m | [
90,
45,
120,
90
] | Parse duration strings like '1h30m', '45m', or '2h' into a JSON list of total minutes. |
cmsvgmejh01qmg4p2udndng9m | contributor_item | Submission NDNG9M | false | import csv, io, json
def transform(text):
reader = csv.reader(io.StringIO(text.strip()))
rows = [row for row in reader]
return json.dumps(rows) | "Smith, John",42,"Boston, MA"
"Doe, Jane",31,"Austin, TX" | [
[
"Smith, John",
"42",
"Boston, MA"
],
[
"Doe, Jane",
"31",
"Austin, TX"
]
] | Parse CSV rows where fields may be quoted and contain embedded commas, converting to a JSON list of [name, age, city] arrays. |
cmsvgmejh01qog4p2herc2dtv | contributor_item | Submission RC2DTV | false | import json
from collections import defaultdict
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
totals = defaultdict(int)
for line in lines:
name, qty = line.split(":")
totals[name] += int(qty)
return json.dumps(dict(sorted(totals.items()))) | apple:3
banana:5
apple:2
cherry:1
banana:1 | {
"apple": 5,
"banana": 6,
"cherry": 1
} | Sum quantities per fruit name from 'name:qty' lines and return a JSON object sorted by name. |
cmsvgmejh01qlg4p2598bkeam | contributor_item | Submission 8BKEAM | false | import json
def transform(text):
stripped = text.strip()
words = stripped.split()
char_count = len(stripped.replace(" ", ""))
return json.dumps({"word_count": len(words), "char_count": char_count}) | The quick brown fox jumps over the lazy dog. The dog barks. | {
"word_count": 12,
"char_count": 48
} | Compute word count and character count (excluding spaces) of a paragraph, returned as a JSON object. |
cmsvgmejh01q7g4p20jsri729 | contributor_item | Submission SRI729 | false | def transform(text):
return " ".join(word[::-1] for word in text.strip().split()) | the quick brown fox | "eht kciuq nworb xof" | Reverse each word's letters individually while preserving word order. |
cmsvgmejh01qag4p2a42mwj2q | contributor_item | Submission 2MWJ2Q | false | import json
def transform(text):
lines = [l for l in text.strip("\n").split("\n") if l.strip()]
result = []
for line in lines:
level = 0
while line[level] == "#":
level += 1
result.append({"level": level, "text": line[level:].strip()})
return json.dumps(result) | # Title
## Section A
## Section B
### Subsection B1
| [
{
"level": 1,
"text": "Title"
},
{
"level": 2,
"text": "Section A"
},
{
"level": 2,
"text": "Section B"
},
{
"level": 3,
"text": "Subsection B1"
}
] | Convert a Markdown heading outline (# levels) into a JSON list of {level, text} objects. |
cmsvgmejh01qeg4p2c5rxjp1u | contributor_item | Submission RXJP1U | false | import json
from collections import defaultdict
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
groups = defaultdict(list)
for line in lines:
fields = dict(p.split("=") for p in line.split("|"))
groups[fields["dept"]].append(fields)
return json.dumps(dict... | dept=eng|name=Alice|role=SWE
dept=eng|name=Bob|role=Manager
dept=sales|name=Carol|role=Rep | {
"eng": [
{
"dept": "eng",
"name": "Alice",
"role": "SWE"
},
{
"dept": "eng",
"name": "Bob",
"role": "Manager"
}
],
"sales": [
{
"dept": "sales",
"name": "Carol",
"role": "Rep"
}
]
} | Parse pipe-delimited key=value log lines and group the records into a JSON object keyed by 'dept'. |
cmsvgmejh01qgg4p283n790qp | contributor_item | Submission N790QP | false | import json, re
def transform(text):
pairs = re.findall(r"<(\w+)>(.*?)</\1>", text.strip())
return json.dumps(dict(pairs)) | <name>Alice</name><age>30</age><city>Boston</city> | {
"name": "Alice",
"age": "30",
"city": "Boston"
} | Parse simple flat XML-like tags (no nesting or attributes) into a JSON object. |
cmsvgmejh01qhg4p26docwie0 | contributor_item | Submission OCWIE0 | false | import re, json
def transform(text):
nums = [int(n) for n in re.findall(r"\d+", text)]
product = 1
for n in nums:
product *= n
return json.dumps({"sum": sum(nums), "product": product}) | There are 12 apples, 7 oranges, and 100 bananas in stock. | {
"sum": 119,
"product": 8400
} | Extract all integers from free text and return their sum and product as a JSON object. |
cmsvgmejg01q5g4p25k8oy8vr | contributor_item | Submission 8OY8VR | false | import json, csv, io
def transform(text):
data = json.loads(text)
out = io.StringIO()
writer = csv.DictWriter(out, fieldnames=list(data[0].keys()))
writer.writeheader()
for row in data:
writer.writerow(row)
return out.getvalue().strip() | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] | "name,age\r\nAlice,30\r\nBob,25" | Convert a JSON array of flat objects into a CSV string with a header row. |
cmsvgmejh01qbg4p24y19jwpb | contributor_item | Submission 19JWPB | false | import json
def transform(text):
lines = [l for l in text.strip().split("\n") if l.strip()]
result = []
ops = {"+": lambda a, b: a + b, "-": lambda a, b: a - b, "*": lambda a, b: a * b, "/": lambda a, b: a / b}
for line in lines:
a, op, b = line.split()
result.append(ops[op](float(a), f... | 3 + 4
10 - 2
6 * 7
20 / 4 | [
7,
8,
42,
5
] | Parse simple two-operand arithmetic expressions (one per line) and return a JSON list of computed results. |
cmsvhbl3101tlg4p25tg22xp6 | contributor_item | Submission G22XP6 | false | import json
def transform(text):
data = json.loads(text)
total = sum(item["price"] for item in data)
return str(total) | [{"price": 10}, {"price": 20}, {"price": 5}] | 35 | Parse a JSON array of objects and return the sum of the 'price' field as a string. |
cmsvhbl3101tmg4p2o30murlp | contributor_item | Submission 0MURLP | false | def transform(text):
lines = [l[2:] for l in text.strip().split("\n") if l.startswith("- ")]
return "\n".join(f"{i+1}. {item}" for i, item in enumerate(lines)) | - apple
- banana
- cherry | "1. apple\n2. banana\n3. cherry" | Convert a markdown bullet list (lines starting with '- ') into a numbered plain text list ('1. apple', etc.), joined by newlines. |
cmsvhbl3101tog4p2mja058ey | contributor_item | Submission A058EY | false | def transform(text):
lines = text.split("\n")
return "\n".join("|".join(line.split("\t")) for line in lines) | a b c
d e f | "a|b|c\nd|e|f" | Convert tab-separated rows of text into pipe-separated rows ('|' between fields), preserving row order. |
cmsvhbl3101trg4p2dgp0wbkl | contributor_item | Submission P0WBKL | false | from collections import Counter
def transform(text):
words = text.lower().split()
counts = Counter(words)
ordered = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))
return "\n".join(f"{w}:{c}" for w, c in ordered) | the quick brown fox the lazy dog the fox | "the:3\nfox:2\nbrown:1\ndog:1\nlazy:1\nquick:1" | Count word frequencies (case-insensitive) and return lines 'word:count' sorted by count descending then word ascending, joined by newlines. |
cmsvhbl3101tsg4p29mzohtkf | contributor_item | Submission ZOHTKF | false | def transform(text):
fs = [float(x) for x in text.split(",")]
cs = [round((f - 32) * 5 / 9, 1) for f in fs]
return ",".join(str(c) for c in cs) | 32,68,100,212 | "0.0,20.0,37.8,100.0" | Parse a comma-separated list of Fahrenheit temperatures and return a comma-separated list of Celsius equivalents rounded to 1 decimal place. |
cmsvhbl3101ttg4p26as50fln | contributor_item | Submission S50FLN | false | import ast
def transform(text):
data = ast.literal_eval(text)
return repr({v: k for k, v in data.items()}) | {'a': 1, 'b': 2, 'c': 3} | "{1: 'a', 2: 'b', 3: 'c'}" | Parse a Python dict literal with unique integer values and return the value-to-key inverse mapping (as repr). |
cmsvhbl3101tkg4p2yi4gcge0 | contributor_item | Submission 4GCGE0 | false | def transform(text):
lines = text.strip().split("\n")
header = lines[0].split(",")
result = []
for line in lines[1:]:
values = line.split(",")
result.append(dict(zip(header, values)))
return result | name,age
Alice,30
Bob,25 | [
{
"age": "30",
"name": "Alice"
},
{
"age": "25",
"name": "Bob"
}
] | Parse CSV text (comma-separated, first row header) into a list of dicts mapping header to value; keep age as a string. |
cmsvhbl3101tpg4p2kjzlvwca | contributor_item | Submission ZLVWCA | false | import re
def transform(text):
nums = [int(n) for n in re.findall(r"-?\d+", text)]
return sum(nums) | I have 3 apples, 5 oranges and lost 2 along the way. | 10 | Extract all integers appearing in the text and return their sum as an int. |
cmsvhbl3101tng4p2mfzkdjfy | contributor_item | Submission ZKDJFY | false | import ast
def transform(text):
data = ast.literal_eval(text)
def to_camel(k):
parts = k.split("_")
return parts[0] + "".join(p.capitalize() for p in parts[1:])
return repr({to_camel(k): v for k, v in data.items()}) | {'first_name': 'Alice', 'last_name': 'Smith'} | "{'firstName': 'Alice', 'lastName': 'Smith'}" | Parse a Python dict literal with snake_case keys and return a new dict literal (as its repr) with camelCase keys, same values. |
cmsvhbl3101tqg4p29zd29kj9 | contributor_item | Submission D29KJ9 | false | import ast
def flatten(lst):
result = []
for item in lst:
if isinstance(item, list):
result.extend(flatten(item))
else:
result.append(item)
return result
def transform(text):
data = ast.literal_eval(text)
return repr(flatten(data)) | [[1, 2], [3, [4, 5]], 6] | [
1,
2,
3,
4,
5,
6
] | Parse a Python list literal that may contain nested lists and return a fully flattened list (as its repr). |
cmsvhc1w301tvg4p2vlyn9w3t | contributor_item | Submission YN9W3T | false | def transform(text):
result = {}
for line in text.strip().split("\n"):
k, v = line.split("=", 1)
if v == "true":
v = True
elif v == "false":
v = False
elif v.isdigit():
v = int(v)
result[k] = v
return repr(result) | host=localhost
port=8080
debug=true | "{'host': 'localhost', 'port': 8080, 'debug': True}" | Parse simple 'key=value' lines into a dict, converting 'true'/'false' to booleans and numeric strings to ints, and return the dict's repr. |
cmsvhc1w301u1g4p2rolne3zd | contributor_item | Submission LNE3ZD | false | import ast
def transform(text):
data = ast.literal_eval(text)
result = {"even": [], "odd": []}
for n in data:
if n % 2 == 0:
result["even"].append(n)
else:
result["odd"].append(n)
return repr(result) | [1, 2, 3, 4, 5, 6, 7] | "{'even': [2, 4, 6], 'odd': [1, 3, 5, 7]}" | Parse a Python list literal of integers and bucket them into a dict with keys 'even' and 'odd', each mapping to a list of the matching numbers in original order, returned as repr. |
cmsvhc1w301tyg4p221p80khb | contributor_item | Submission P80KHB | false | import ast
def transform(text):
data = ast.literal_eval(text)
if not data:
return repr([])
result = []
prev = data[0]
count = 1
for item in data[1:]:
if item == prev:
count += 1
else:
result.append((prev, count))
prev = item
... | [1, 1, 1, 2, 2, 3, 1, 1] | "[(1, 3), (2, 2), (3, 1), (1, 2)]" | Parse a Python list literal and run-length-encode consecutive duplicates into a list of (value, count) tuples, returned as repr. |
cmsvhc1w301u2g4p26dvueeb9 | contributor_item | Submission VUEEB9 | false | import re
def transform(text):
return re.sub(r"\d+", lambda m: "X" * len(m.group()), text) | Card ending in 4242, call 555-1234 today | "Card ending in XXXX, call XXX-XXXX today" | Replace every maximal run of digits in the text with the same number of 'X' characters, leaving everything else unchanged. |
cmsvhc1w301tug4p25dk2lg22 | contributor_item | Submission K2LG22 | false | import ast
def transform(text):
data = ast.literal_eval(text)
ordered = sorted(data, key=lambda t: (-t[1], t[0]))
lines = [f"{i+1}. {name} - {score}" for i, (name, score) in enumerate(ordered)]
return "\n".join(lines) | [('Alice', 90), ('Bob', 75), ('Carol', 90)] | "1. Alice - 90\n2. Carol - 90\n3. Bob - 75" | Parse a list of (name, score) tuples and produce leaderboard text, one line per entry as "rank. name - score", sorted by score descending then name ascending, numbering rows sequentially (no shared ranks for ties). |
cmsvhc1w301twg4p2zwgsv66y | contributor_item | Submission GSV66Y | false | def transform(text):
parts = [p.strip() for p in text.split(",")]
out = []
for p in parts:
count_str, noun = p.split(" ", 1)
count = int(count_str)
if count != 1:
noun = noun + "s"
out.append(f"{count} {noun}")
return ", ".join(out) | 3 cat, 1 dog, 5 bird | "3 cats, 1 dog, 5 birds" | Parse a comma-separated 'count noun' list and return a comma-separated string where nouns with count != 1 get an 's' appended (simple pluralization). |
cmsvhc1w301tzg4p28sm3lh5x | contributor_item | Submission M3LH5X | false | import re
def transform(text):
m = re.match(r"(\d+)h(\d+)m", text)
hours, minutes = int(m.group(1)), int(m.group(2))
return hours * 60 + minutes | 2h15m | 135 | Parse a duration string in the form '<hours>h<minutes>m' (both parts always present) and return the total number of minutes as an int. |
cmsvhc1w301txg4p2magrf3px | contributor_item | Submission GRF3PX | false | import json
def transform(text):
data = json.loads(text)
keys = list(data[0].keys())
lines = [",".join(keys)]
for item in data:
lines.append(",".join(str(item[k]) for k in keys))
return "\n".join(lines) | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] | "name,age\nAlice,30\nBob,25" | Parse a JSON array of objects with the same keys and return CSV text: header row from keys (in first-seen order), then one row per object, comma-separated. |
cmsvhc1w301u3g4p2l4kg80ry | contributor_item | Submission KG80RY | false | import ast
def transform(text):
data = ast.literal_eval(text)
ranges = sorted(data, key=lambda t: t[0])
merged = []
for start, end in ranges:
if merged and start <= merged[-1][1]:
merged[-1] = (merged[-1][0], max(merged[-1][1], end))
else:
merged.append((start, e... | [(1, 3), (2, 6), (8, 10), (15, 18)] | "[(1, 6), (8, 10), (15, 18)]" | Parse a list of (start, end) integer range tuples and merge any overlapping or touching ranges (touching means end of one equals start of next), returning the merged list of tuples sorted by start, as repr. |
cmsvhc1w301u0g4p2eprua6h7 | contributor_item | Submission RUA6H7 | false | def transform(text):
small = {"of", "the", "and", "a"}
words = text.split()
result = []
for i, w in enumerate(words):
if i > 0 and w in small:
result.append(w)
else:
result.append(w.capitalize())
return " ".join(result) | the lord of the rings and a tale of two cities | "The Lord of the Rings and a Tale of Two Cities" | Title-case the given sentence, but keep the small words 'of', 'the', 'and', 'a' lowercase unless they are the first word. |
cmsvmgr2k01wig4p2wlzo76hx | contributor_item | Submission ZO76HX | false | def transform(text):
result = {}
section = None
for line in text.strip().split('\n'):
line = line.strip()
if not line:
continue
if line.startswith('[') and line.endswith(']'):
section = line[1:-1]
result[section] = {}
else:
k, v... | [server]
host=localhost
port=8080
[client]
timeout=30 | "{'server': {'host': 'localhost', 'port': '8080'}, 'client': {'timeout': '30'}}" | Parse a simple INI-style config (sections in brackets, key=value lines) into a nested dict and return its repr. |
cmsvmgr2k01wlg4p2pdqjoqj0 | contributor_item | Submission QJOQJ0 | false | import ast
def transform(text):
list_part, n_part = text.split('|')
data = ast.literal_eval(list_part)
n = int(n_part) % len(data)
return repr(data[n:] + data[:n]) | [1, 2, 3, 4, 5]|2 | [
3,
4,
5,
1,
2
] | Parse 'LIST|N' where LIST is a Python list literal and N is an int; rotate the list left by N positions and return its repr. |
cmsvmgr2k01whg4p266tbsf97 | contributor_item | Submission TBSF97 | false | import re
def transform(text):
items = re.findall(r'<item>(.*?)</item>', text)
return ','.join(items) | <root><item>apple</item><item>banana</item><item>cherry</item></root> | "apple,banana,cherry" | Extract the text content of every <item> tag and return a comma-separated string. |
cmsvmgr2k01wng4p23zz0rpvz | contributor_item | Submission Z0RPVZ | false | def transform(text):
words = text.split()
return ' '.join(w[::-1] for w in words) | hello world foo | "olleh dlrow oof" | Reverse the characters within each word but keep the words in their original order, joined by spaces. |
cmsvmgr2k01wgg4p27e5s64nl | contributor_item | Submission 5S64NL | false | def transform(text):
parts = text.split(',')
return ','.join(p.replace('_', '-') for p in parts) | first_name,last_name,phone_number | "first-name,last-name,phone-number" | Convert a comma-separated list of snake_case identifiers into kebab-case (underscores to hyphens). |
cmsvmgr2k01wjg4p2274lso96 | contributor_item | Submission 4LSO96 | false | import re
def roman_to_int(s):
vals = {'I': 1, 'V': 5, 'X': 10}
total = 0
for i in range(len(s)):
v = vals[s[i]]
if i + 1 < len(s) and v < vals[s[i + 1]]:
total -= v
else:
total += v
return total
def transform(text):
tokens = re.findall(r'\b[IVX]+\b'... | Chapter IV covers section II and III, but not I. | 10 | Extract all standalone Roman numerals (I, II, III, IV, uppercase, word-bounded) from the text and return their sum as an int, converting each properly. |
cmsvmgr2k01wkg4p2wy2bthzg | contributor_item | Submission 2BTHZG | false | def transform(text):
fs = [float(x) for x in text.split(',')]
ks = [round((f - 32) * 5 / 9 + 273.15, 2) for f in fs]
return ','.join(str(k) for k in ks) | 32,212,98.6 | "273.15,373.15,310.15" | Parse a comma-separated list of Fahrenheit temperatures and return a comma-separated list of Kelvin equivalents rounded to 2 decimals. |
cmsvmgr2k01wmg4p2694v2s5u | contributor_item | Submission 4V2S5U | false | def transform(text):
rows = [[int(x) for x in line.split(',')] for line in text.strip().split('\n')]
cols = list(zip(*rows))
return '\n'.join(','.join(str(x) for x in col) for col in cols) | 1,2,3
4,5,6 | "1,4\n2,5\n3,6" | Parse comma-separated rows of numbers (one row per line) and return the transposed matrix in the same comma/newline format. |
cmsvmgr2k01wog4p2fabjnwfa | contributor_item | Submission BJNWFA | false | def transform(text):
vowels = set('aeiouAEIOU')
words = text.split()
return repr({w: sum(1 for c in w if c in vowels) for w in words}) | sky rhythm apple | "{'sky': 0, 'rhythm': 0, 'apple': 2}" | Split text into words and count vowels (a, e, i, o, u, case-insensitive) in each word, returning a dict of word to vowel count as repr. |
cmsvmgr2k01wpg4p2zlfk1nsl | contributor_item | Submission FK1NSL | false | import re
def transform(text):
parts = text.split(',')
def conv(s):
return re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower()
return ','.join(conv(p) for p in parts) | firstName,lastName,phoneNumber | "first_name,last_name,phone_number" | Convert a comma-separated list of camelCase identifiers into snake_case. |
cmsvmky1u01y1g4p2bdbrh3gk | contributor_item | Submission BRH3GK | false | import json
def flatten(d, prefix=''):
result = {}
for k, v in d.items():
key = f'{prefix}.{k}' if prefix else k
if isinstance(v, dict):
result.update(flatten(v, key))
else:
result[key] = v
return result
def transform(text):
data = json.loads(text)
r... | {"a": {"b": 1, "c": {"d": 2}}} | "{'a.b': 1, 'a.c.d': 2}" | Parse a nested JSON object and flatten it into a single-level dict with dot-notation keys, returned as its repr. |
cmsvmky1t01xxg4p28ixqsztk | contributor_item | Submission XQSZTK | false | import ast
def transform(text):
data = ast.literal_eval(text)
lines = ['name,age']
for name, age in data:
lines.append(f'{name},{age}')
return '\n'.join(lines) | [('Alice', 30), ('Bob', 25)] | "name,age\nAlice,30\nBob,25" | Parse a Python list of (name, age) tuples and return CSV text with header 'name,age' then one row per tuple. |
cmsvmky1t01xzg4p2dlyjeb2p | contributor_item | Submission YJEB2P | false | def transform(text):
nums = [int(x) for x in text.split(',')]
return sum(nums) | 001,022,333,004 | 360 | Parse a comma-separated list of zero-padded number strings and return their sum as an int. |
cmsvmky1t01xug4p24zso2msr | contributor_item | Submission SO2MSR | false | import re
def transform(text):
amounts = [float(m) for m in re.findall(r'\$(\d+\.\d{2})', text)]
return round(sum(amounts), 2) | Item A costs $12.50, Item B costs $7.25, and shipping is $3.00. | 22.75 | Extract all dollar amounts (format $X.XX) from the text and return their total as a float rounded to 2 decimals. |
cmsvmky1t01xwg4p2bze9yjq0 | contributor_item | Submission E9YJQ0 | false | def transform(text):
result = {}
for pair in text.split(';'):
k, v = pair.split(':', 1)
result[k] = v
return repr(result) | name:Alice;age:30;city:NYC | "{'name': 'Alice', 'age': '30', 'city': 'NYC'}" | Parse a semicolon-separated list of key:value pairs into a dict and return its repr. |
cmsvmky1t01xvg4p2ige5h4zl | contributor_item | Submission E5H4ZL | false | def transform(text):
stopwords = {'the', 'a', 'and', 'over'}
words = text.split()
return sum(1 for w in words if w not in stopwords) | the quick brown fox jumps over the lazy dog and a cat | 7 | Count words in the text excluding a small stopword list ('the', 'a', 'and', 'over'), returning the count as an int. |
cmsvmky1u01y2g4p2gyzy6z1i | contributor_item | Submission ZY6Z1I | false | def transform(text):
result = {'letters': 0, 'digits': 0, 'other': 0}
for ch in text:
if ch.isalpha():
result['letters'] += 1
elif ch.isdigit():
result['digits'] += 1
else:
result['other'] += 1
return repr(result) | Hello123! World456? | "{'letters': 10, 'digits': 6, 'other': 3}" | Count how many characters in the text are letters, digits, or 'other' (neither), returning a dict repr with keys 'letters', 'digits', 'other'. |
cmsvmky1t01xyg4p2c6h1hfv9 | contributor_item | Submission H1HFV9 | false | def transform(text):
emails = text.split(',')
domains = []
seen = set()
for e in emails:
d = e.split('@')[1]
if d not in seen:
seen.add(d)
domains.append(d)
return ','.join(domains) | alice@example.com,bob@test.org,carol@example.com | "example.com,test.org" | Parse a comma-separated list of email addresses and return a comma-separated list of unique domains in first-seen order. |
cmsvmky1t01y0g4p2h8kj78qz | contributor_item | Submission KJ78QZ | false | def transform(text):
words = text.split()
lines = []
current = ''
for w in words:
candidate = (current + ' ' + w).strip()
if len(candidate) <= 15:
current = candidate
else:
if current:
lines.append(current)
current = w
if cu... | the quick brown fox jumps over the lazy dog | "the quick brown\nfox jumps over\nthe lazy dog" | Wrap the text into lines of at most 15 characters, breaking only on word boundaries, joined by newlines. |
cmsvmky1u01y3g4p20uo3q8bo | contributor_item | Submission O3Q8BO | false | def transform(text):
lines = text.strip().split('\n')
result = []
i = 0
while i < len(lines):
j = i
while j < len(lines) and lines[j] == lines[i]:
j += 1
count = j - i
if count == 1:
result.append(lines[i])
else:
result.append(f... | apple
apple
apple
banana
banana
cherry | "apple x3\nbanana x2\ncherry" | Given lines of text, collapse consecutive duplicate lines into 'line xN' format (omit xN if count is 1), one per output line. |
cmsvniv0d0205g4p2gw687fgh | contributor_item | Submission 687FGH | false | import json
def transform(text):
return json.dumps(text.split(',')) | apple,banana,cherry,42 | [
"apple",
"banana",
"cherry",
"42"
] | Parse a single comma-separated line and return it as a JSON array string. |
cmsvniv0d0207g4p2x1u9as4q | contributor_item | Submission U9AS4Q | false | def transform(text):
counts = {}
for ch in text:
if not ch.isalnum() and not ch.isspace():
counts[ch] = counts.get(ch, 0) + 1
return repr(counts) | Hello, world! How are you? Fine; thanks. | "{',': 1, '!': 1, '?': 1, ';': 1, '.': 1}" | Count each punctuation character (non-alphanumeric, non-space) occurrence, return dict repr. |
cmsvniv0d020eg4p2rcmgekc1 | contributor_item | Submission MGEKC1 | false | def transform(text):
nums = [int(x) for x in text.split(',')]
return sum(n * n for n in nums) | 1,2,3,4,5 | 55 | Parse a comma-separated list of integers and return the sum of their squares. |
cmsvniv0d020gg4p2ms0u2k7p | contributor_item | Submission 0U2K7P | false | def transform(text):
filename = text.rsplit('/', 1)[-1]
return filename.rsplit('.', 1)[0] | /usr/local/bin/script.tar.gz | "script.tar" | Given a file path, extract just the filename without its final extension. |
cmsvniv0d020lg4p2r637nls8 | contributor_item | Submission 37NLS8 | false | def transform(text):
vals = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
total = 0
for i in range(len(text)):
v = vals[text[i]]
if i + 1 < len(text) and v < vals[text[i + 1]]:
total -= v
else:
total += v
return total | MMXIV | 2014 | Convert a single standalone Roman numeral string into its integer value. |
cmsvniv0d020kg4p274qrofe9 | contributor_item | Submission QROFE9 | false | def transform(text):
nums = [int(x) for x in text.split(',')]
running = []
total = 0
for n in nums:
total += n
running.append(total)
return ','.join(str(x) for x in running) | 3,1,4,1,5 | "3,4,8,9,14" | Parse a comma-separated list of integers and return the running cumulative sum, comma-separated. |
cmsvniv0d0204g4p2cl364vva | contributor_item | Submission 364VVA | false | import re
def transform(text):
nums = [int(x) for x in re.findall(r'\d+', text)]
return round(sum(nums) / len(nums), 2) | Order 12 items at 3 dollars, plus 7 more at 5 dollars | 6.75 | Extract all integers from the text and return their average rounded to 2 decimals. |
cmsvniv0d0206g4p2zr32p4nn | contributor_item | Submission 32P4NN | false | def transform(text):
return ' '.join(w.capitalize() for w in text.split()) | the great gatsby is a classic novel | "The Great Gatsby Is A Classic Novel" | Convert each word in the sentence to title case (first letter uppercase). |
cmsvniv0d0209g4p2m6xa4gdx | contributor_item | Submission XA4GDX | false | def transform(text):
return ' '.join(reversed(text.split())) | the quick brown fox jumps | "jumps fox brown quick the" | Reverse the order of words in the sentence (characters within words stay the same). |
cmsvniv0d0208g4p2lzsthtwl | contributor_item | Submission STHTWL | false | def transform(text):
lines = text.strip().split('\n')
header = lines[0].split('|')
rows = []
for line in lines[1:]:
values = line.split('|')
rows.append(dict(zip(header, values)))
return repr(rows) | name|age|city
Alice|30|NYC
Bob|25|LA | "[{'name': 'Alice', 'age': '30', 'city': 'NYC'}, {'name': 'Bob', 'age': '25', 'city': 'LA'}]" | Parse a pipe-delimited table (first line is header) into a list of dicts, return its repr. |
cmsvniv0d020ag4p26dgznb69 | contributor_item | Submission GZNB69 | false | def transform(text):
cs = [float(x) for x in text.split(',')]
fs = [round(c * 9 / 5 + 32, 1) for c in cs]
return ','.join(str(f) for f in fs) | 0,20,37,100 | "32.0,68.0,98.6,212.0" | Parse a comma-separated list of Celsius temperatures and return Fahrenheit equivalents, comma-separated, rounded to 1 decimal. |
cmsvniv0d020ig4p22eq3rbjf | contributor_item | Submission Q3RBJF | false | def transform(text):
result = {}
for pair in text.split('&'):
k, v = pair.split('=')
result[k] = v
return repr(result) | a=1&b=2&c=3 | "{'a': '1', 'b': '2', 'c': '3'}" | Parse a URL query string (key=value pairs joined by &) into a dict, return its repr. |
cmsvniv0d020mg4p27gvf81ou | contributor_item | Submission VF81OU | false | def transform(text):
return ''.join(ch for ch in text if ch.lower() not in 'aeiou') | The Quick Brown Fox Jumps | "Th Qck Brwn Fx Jmps" | Remove all vowels (a, e, i, o, u, case-insensitive) from the text. |
cmsvniv0d020jg4p2ohejrmf9 | contributor_item | Submission EJRMF9 | false | import re
def transform(text):
return ','.join(re.findall(r'\b[A-Z][a-zA-Z]*\b', text)) | Alice went to Paris with Bob and saw the Eiffel Tower | "Alice,Paris,Bob,Eiffel,Tower" | Extract all capitalized words (starting with an uppercase letter) from the text, comma-separated in order. |
cmsvniv0d0203g4p2zfqv86qa | contributor_item | Submission QV86QA | false | def transform(text):
parts = text.split(',')
def conv(s):
words = s.split('-')
return words[0] + ''.join(w.capitalize() for w in words[1:])
return ','.join(conv(p) for p in parts) | first-name,last-name,phone-number | "firstName,lastName,phoneNumber" | Convert a comma-separated list of kebab-case identifiers into camelCase. |
cmsvniv0d020bg4p2hx08c7kw | contributor_item | Submission 08C7KW | false | import re
def transform(text):
return ','.join(re.findall(r'#\w+', text)) | Loving the #sunset and #beach vibes today! #travel | "#sunset,#beach,#travel" | Extract all hashtags from the text and return them comma-separated in order of appearance. |
cmsvniv0d020cg4p2vnygneyl | contributor_item | Submission YGNEYL | false | def transform(text):
result = {}
for group in text.split(';'):
k, v = group.split(',')
result[k] = v
return repr(result) | a,1;b,2;c,3 | "{'a': '1', 'b': '2', 'c': '3'}" | Parse a semicolon-separated list of comma-separated key,value pairs into a dict, return its repr. |
cmsvniv0d020dg4p2pgd0p43d | contributor_item | Submission D0P43D | false | def transform(text):
return ' '.join(w[:4] for w in text.split()) | elephant giraffe hippopotamus cat | "elep gira hipp cat" | Truncate each word in the text to a maximum of 4 characters, keeping words joined by spaces. |
cmsvniv0d020fg4p2vdvzfjrb | contributor_item | Submission VZFJRB | false | def transform(text):
nums = [str(int(b, 2)) for b in text.split(',')]
return ','.join(nums) | 101,1111,1000,11 | "5,15,8,3" | Parse a comma-separated list of binary number strings and return their decimal equivalents, comma-separated. |
cmsvniv0d020hg4p22uf328u8 | contributor_item | Submission F328U8 | false | import re
def transform(text):
parts = re.split(r'[.!?]', text)
return sum(1 for p in parts if p.strip()) | Hello world. How are you? I am fine! Great. | 4 | Count the number of sentences in the text (split on '.', '!', '?', ignoring empty fragments). |
cmsvnvuek0234g4p2zvoisd0i | contributor_item | Submission OISD0I | false | def transform(text):
lines = text.split('\n')
return '\n'.join(l[::-1] for l in lines) | hello
world
foo | "olleh\ndlrow\noof" | Reverse the characters of each line in the text, keeping the line order unchanged, joined by newlines. |
cmsvnvuek022yg4p2k1hru9lx | contributor_item | Submission HRU9LX | false | import json
def transform(text):
matrix = json.loads(text)
return sum(matrix[i][i] for i in range(len(matrix))) | [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | 15 | Parse a JSON matrix (list of lists) and return the sum of its main diagonal. |
cmsvnvuek022wg4p20njx3lwk | contributor_item | Submission JX3LWK | false | def transform(text):
parts = text.split(',')
def conv(s):
return ''.join(w.capitalize() for w in s.split('_'))
return ','.join(conv(p) for p in parts) | first_name,last_name,phone_number | "FirstName,LastName,PhoneNumber" | Convert a comma-separated list of snake_case identifiers into PascalCase. |
cmsvnvuek023dg4p2oss3d99s | contributor_item | Submission S3D99S | false | def transform(text):
return sum(1 for w in text.split() if len(w) > 5) | the quick brown fox jumps over lazy elephant | 1 | Count how many words in the text have more than 5 characters. |
cmsvnvuek0232g4p21i7e6ten | contributor_item | Submission 7E6TEN | false | def transform(text):
ranges = []
for part in text.split(','):
a, b = part.split('-')
ranges.append([int(a), int(b)])
ranges.sort(key=lambda r: r[0])
merged = [ranges[0]]
for start, end in ranges[1:]:
if start <= merged[-1][1]:
merged[-1][1] = max(merged[-1][1], en... | 1-3,2-5,8-10,9-12 | "1-5,8-12" | Parse a comma-separated list of N-M numeric ranges, merge overlapping ones, and return the merged ranges as N-M pairs comma-separated. |
cmsvnvuek0237g4p23gub7swa | contributor_item | Submission UB7SWA | false | def transform(text):
total = 0.0
for part in text.split(','):
count, price = part.split('x')
total += int(count) * float(price)
return total | 3x10,2x5,4x2.5 | 50 | Parse a comma-separated list of 'COUNTxPRICE' entries and return the total cost as a float. |
cmsvnvuek0238g4p2s3smcml9 | contributor_item | Submission SMCML9 | false | import re
def transform(text):
urls = text.split(',')
domains = [re.match(r'https?://([^/]+)', u).group(1) for u in urls]
return ','.join(domains) | https://www.example.com/page,http://api.test.org/v1,https://sub.domain.io | "www.example.com,api.test.org,sub.domain.io" | Parse a comma-separated list of URLs and return their domain names (host part, without scheme or path), comma-separated. |
cmsvnvuek022xg4p2ptnm6qcj | contributor_item | Submission NM6QCJ | false | import re
def transform(text):
return re.sub(r'\d{3}-\d{3}-\d{4}', 'XXX-XXX-XXXX', text) | Call me at 555-123-4567 or 555-987-6543 anytime. | "Call me at XXX-XXX-XXXX or XXX-XXX-XXXX anytime." | Find all phone numbers (format XXX-XXX-XXXX) in the text and replace their digits with X, keeping hyphens. |
cmsvnvuek022zg4p2ohc0kt7n | contributor_item | Submission C0KT7N | false | def transform(text):
return ''.join(w[0].upper() for w in text.split()) | National Aeronautics and Space Administration | "NAASA" | Convert a phrase into an acronym using the first letter of each word, uppercase, no separators. |
cmsvnvuek0231g4p2pnsj3qmw | contributor_item | Submission SJ3QMW | false | def transform(text):
ks = [float(x) for x in text.split(',')]
cs = [round(k - 273.15, 2) for k in ks]
return ','.join(str(c) for c in cs) | 273.15,300,373.15 | "0.0,26.85,100.0" | Parse a comma-separated list of Kelvin temperatures and return Celsius equivalents, comma-separated, rounded to 2 decimals. |
cmsvnvuek0233g4p2rhlw568u | contributor_item | Submission LW568U | false | from collections import Counter
def transform(text):
words = text.split()
return Counter(words).most_common(1)[0][0] | the cat sat on the mat the cat ran | "the" | Find the most frequently occurring word in the text and return it. |
cmsvnvuek0230g4p2tt02spn7 | contributor_item | Submission 02SPN7 | false | import re
def transform(text):
return ','.join(re.findall(r'\(([^)]*)\)', text)) | The result (computed carefully) was correct (finally) | "computed carefully,finally" | Extract all text found inside parentheses and return them comma-separated in order. |
cmsvnvuek0236g4p291tenu3l | contributor_item | Submission TENU3L | false | def transform(text):
scores = [int(x) for x in text.split(',')]
def grade(s):
if s >= 90:
return 'A'
if s >= 80:
return 'B'
if s >= 70:
return 'C'
if s >= 60:
return 'D'
return 'F'
return ','.join(grade(s) for s in score... | 95,82,71,60,45 | "A,B,C,D,F" | Parse a comma-separated list of numeric scores (0-100) and convert each to a letter grade (A:90+, B:80+, C:70+, D:60+, F:below 60), comma-separated. |
cmsvnvuek0235g4p28xk4h609 | contributor_item | Submission K4H609 | false | import re
def transform(text):
pairs = re.findall(r'"([^"]*)"|\'([^\']*)\'', text)
return ','.join(a if a else b for a, b in pairs) | She said "hello" and then 'goodbye' quickly | "hello,goodbye" | Extract all substrings enclosed in single or double quotes, comma-separated in order. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.