submissionId stringlengths 25 25 | title stringlengths 17 17 | payload dict |
|---|---|---|
cmsmt6sqa003sdmp2cahx7s60 | Submission HX7S60 | {
"code": "def sum_by_key(records):\n totals = {}\n for r in records:\n totals[r['cat']] = totals.get(r['cat'], 0) + r['amt']\n return totals",
"input": "sum_by_key([{'cat': 'x', 'amt': 5}, {'cat': 'y', 'amt': 2}, {'cat': 'x', 'amt': 3}])",
"language": "Python",
"predicted_output": "{'x': 8, 'y'... |
cmsmt6sqa003tdmp2yconun9n | Submission ONUN9N | {
"code": "def all_balanced(strings):\n pairs = {')': '(', ']': '[', '}': '{'}\n result = []\n for s in strings:\n stack = []\n ok = True\n for ch in s:\n if ch in '([{':\n stack.append(ch)\n elif ch in pairs:\n if not stack or stack.po... |
cmsnc3d7k005k6zp2hj2zuiq0 | Submission 2ZUIQ0 | {
"code": "def compact_ranges(nums):\n if not nums: return []\n out=[]; start=prev=nums[0]\n for x in nums[1:]:\n if x==prev+1: prev=x; continue\n out.append((start,prev)); start=prev=x\n out.append((start,prev)); return out",
"input": "compact_ranges([1,2,3,5,8,9])",
"language": "Python... |
cmsnc3d7k005l6zp2v50vvnda | Submission 0VVNDA | {
"code": "def invert_counts(items):\n d={}\n for x in items: d[x]=d.get(x,0)+1\n return sorted((v,k) for k,v in d.items())",
"input": "invert_counts(['b','a','b','c','a','b'])",
"language": "Python",
"predicted_output": "[(1, 'c'), (2, 'a'), (3, 'b')]"
} |
cmsnc3d7k005m6zp23fioo3ow | Submission IOO3OW | {
"code": "def zigzag(nums):\n return [x if i%2==0 else -x for i,x in enumerate(nums)]",
"input": "zigzag([4,1,-2,3])",
"language": "Python",
"predicted_output": "[4, -1, -2, -3]"
} |
cmsnc3d7k005n6zp2csodixha | Submission ODIXHA | {
"code": "def merge_defaults(defaults, override):\n out=defaults.copy(); out.update({k:v for k,v in override.items() if v is not None}); return out",
"input": "merge_defaults({'a':1,'b':2},{'b':5,'c':None,'d':9})",
"language": "Python",
"predicted_output": "{'a': 1, 'b': 5, 'd': 9}"
} |
cmsnc3d7k005o6zp2dejfcpub | Submission JFCPUB | {
"code": "def window_sums(nums,k):\n if k<=0 or k>len(nums): return []\n s=sum(nums[:k]); out=[s]\n for i in range(k,len(nums)):\n s+=nums[i]-nums[i-k]; out.append(s)\n return out",
"input": "window_sums([2,5,-1,4,3],3)",
"language": "Python",
"predicted_output": "[6, 8, 6]"
} |
cmsnc3d7k005p6zp2rfqiyxyh | Submission QIYXYH | {
"code": "def safe_ints(values):\n out=[]\n for v in values:\n try: out.append(int(v))\n except (ValueError,TypeError): out.append(None)\n return out",
"input": "safe_ints(['12','-3','x',None,'04'])",
"language": "Python",
"predicted_output": "[12, -3, None, None, 4]"
} |
cmsnc3d7k005q6zp2a3ly97qc | Submission LY97QC | {
"code": "def transpose(rows):\n return [list(col) for col in zip(*rows)] if rows else []",
"input": "transpose([[1,2,3],[4,5,6]])",
"language": "Python",
"predicted_output": "[[1, 4], [2, 5], [3, 6]]"
} |
cmsnc3d7k005r6zp2s663vi7e | Submission 63VI7E | {
"code": "def unique_last(items):\n seen=set(); out=[]\n for x in reversed(items):\n if x not in seen: seen.add(x); out.append(x)\n return list(reversed(out))",
"input": "unique_last(['a','b','a','c','b'])",
"language": "Python",
"predicted_output": "['a', 'c', 'b']"
} |
cmsnc3d7k005s6zp2tb93tm85 | Submission 93TM85 | {
"code": "def classify(nums):\n return {'neg':sum(x<0 for x in nums),'zero':sum(x==0 for x in nums),'pos':sum(x>0 for x in nums)}",
"input": "classify([-2,0,3,4,0,-1])",
"language": "Python",
"predicted_output": "{'neg': 2, 'zero': 2, 'pos': 2}"
} |
cmsnc3d7l005t6zp2orp4mrzs | Submission P4MRZS | {
"code": "def rotate_matrix(m):\n return [list(row) for row in zip(*m[::-1])]",
"input": "rotate_matrix([[1,2,3],[4,5,6]])",
"language": "Python",
"predicted_output": "[[4, 1], [5, 2], [6, 3]]"
} |
cmsnc3d7l005u6zp2jw9sxqku | Submission 9SXQKU | {
"code": "def nested_get(obj,path,default=None):\n cur=obj\n for key in path:\n if not isinstance(cur,dict) or key not in cur: return default\n cur=cur[key]\n return cur",
"input": "(nested_get({'a':{'b':7}},['a','b']), nested_get({'a':{}},['a','x'],'missing'))",
"language": "Python",
"p... |
cmsnc3d7l005v6zp2bjn6zgkr | Submission N6ZGKR | {
"code": "def rank_scores(scores):\n vals=sorted(set(scores),reverse=True)\n ranks={v:i+1 for i,v in enumerate(vals)}\n return [ranks[x] for x in scores]",
"input": "rank_scores([90,70,90,50,70])",
"language": "Python",
"predicted_output": "[1, 2, 1, 3, 2]"
} |
cmsnc3d7l005w6zp27h5yuhmv | Submission 5YUHMV | {
"code": "def flatten_once(items):\n out=[]\n for x in items:\n out.extend(x if isinstance(x,list) else [x])\n return out",
"input": "flatten_once([[1,2],3,[],[4,[5]]])",
"language": "Python",
"predicted_output": "[1, 2, 3, 4, [5]]"
} |
cmsnc3d7m005x6zp2tg2qj3f3 | Submission 2QJ3F3 | {
"code": "def diff_keys(a,b):\n keys=set(a)|set(b)\n return sorted(k for k in keys if a.get(k)!=b.get(k))",
"input": "diff_keys({'a':1,'b':2,'d':None},{'a':1,'b':3,'c':4})",
"language": "Python",
"predicted_output": "['b', 'c']"
} |
cmsnc3d7m005y6zp2mc7bf5a7 | Submission 7BF5A7 | {
"code": "def encode_runs(s):\n if not s:return []\n out=[]; ch=s[0]; n=1\n for c in s[1:]:\n if c==ch:n+=1\n else:out.append((ch,n));ch=c;n=1\n out.append((ch,n));return out",
"input": "encode_runs('aaabbccccaa')",
"language": "Python",
"predicted_output": "[('a', 3), ('b', 2), ('c',... |
cmsnc3d7m005z6zp2lzi01jq8 | Submission I01JQ8 | {
"code": "def bucket(nums,size):\n out={}\n for x in nums:\n k=(x//size)*size\n out.setdefault(k,[]).append(x)\n return out",
"input": "bucket([1,9,10,11,19,20],10)",
"language": "Python",
"predicted_output": "{0: [1, 9], 10: [10, 11, 19], 20: [20]}"
} |
cmsnc3d7m00606zp277m1l1vm | Submission M1L1VM | {
"code": "def pairwise_delta(nums):\n return [b-a for a,b in zip(nums,nums[1:])]",
"input": "pairwise_delta([10,13,8,8,20])",
"language": "Python",
"predicted_output": "[3, -5, 0, 12]"
} |
cmsnc3d7m00616zp205npvp25 | Submission NPVP25 | {
"code": "def normalize_record(r):\n return {k.strip().lower(): (v.strip() if isinstance(v,str) else v) for k,v in r.items()}",
"input": "normalize_record({' Name ':' Ada ','AGE':36})",
"language": "Python",
"predicted_output": "{'name': 'Ada', 'age': 36}"
} |
cmsnc3d7m00626zp2niq0ghji | Submission Q0GHJI | {
"code": "def take_until(nums,limit):\n out=[]; total=0\n for x in nums:\n if total+x>limit: break\n out.append(x); total+=x\n return out,total",
"input": "take_until([3,4,5,1],10)",
"language": "Python",
"predicted_output": "([3, 4], 7)"
} |
cmsnc3d7m00636zp2q5zkdrvj | Submission ZKDRVJ | {
"code": "def intersection_ordered(a,b):\n allowed=set(b); seen=set(); out=[]\n for x in a:\n if x in allowed and x not in seen: seen.add(x); out.append(x)\n return out",
"input": "intersection_ordered([3,1,2,3,4,2],[2,3,9])",
"language": "Python",
"predicted_output": "[3, 2]"
} |
cmso86qn900ak6zp2ou1ubwfs | Submission 1UBWFS | {
"code": "def f(xs):\n return [x*x for x in xs if x%2]",
"input": "f([1,2,3,4,5])",
"language": "Python",
"predicted_output": "[1, 9, 25]"
} |
cmso86qn900al6zp2ieg6wc71 | Submission G6WC71 | {
"code": "def f(s):\n return {c:s.count(c) for c in sorted(set(s))}",
"input": "f('banana')",
"language": "Python",
"predicted_output": "{'a': 3, 'b': 1, 'n': 2}"
} |
cmso86qn900am6zp2o1017uh4 | Submission 017UH4 | {
"code": "def f(xs):\n a=0\n for i,x in enumerate(xs): a+=i*x\n return a",
"input": "f([3,4,5])",
"language": "Python",
"predicted_output": "14"
} |
cmso86qn900an6zp22woinimi | Submission OINIMI | {
"code": "def f(n):\n return sum(i for i in range(n+1) if i%3==0)",
"input": "f(10)",
"language": "Python",
"predicted_output": "18"
} |
cmso86qn900ao6zp2ao3ifi6i | Submission 3IFI6I | {
"code": "def f(d):\n return sorted(d.items(), key=lambda p:(-p[1],p[0]))",
"input": "f({'b':2,'a':2,'c':1})",
"language": "Python",
"predicted_output": "[('a', 2), ('b', 2), ('c', 1)]"
} |
cmso86qn900ap6zp2pgftznkt | Submission FTZNKT | {
"code": "def f(xs):\n return list(zip(xs,xs[1:]))",
"input": "f([4,7,9])",
"language": "Python",
"predicted_output": "[(4, 7), (7, 9)]"
} |
cmso86qna00ar6zp21dgmzedj | Submission GMZEDJ | {
"code": "def f(xs):\n return [sum(xs[:i]) for i in range(len(xs)+1)]",
"input": "f([2,-1,3])",
"language": "Python",
"predicted_output": "[0, 2, 1, 4]"
} |
cmso86qna00as6zp27fkmefbi | Submission KMEFBI | {
"code": "def f(n):\n a,b=0,1\n for _ in range(n): a,b=b,a+b\n return a",
"input": "f(8)",
"language": "Python",
"predicted_output": "21"
} |
cmso86qna00at6zp2epzu6444 | Submission ZU6444 | {
"code": "def f(xs):\n return max(enumerate(xs),key=lambda p:p[1])",
"input": "f([5,9,9,2])",
"language": "Python",
"predicted_output": "(1, 9)"
} |
cmso86qna00au6zp20n1dn9eb | Submission 1DN9EB | {
"code": "def f(s):\n return s[::2],s[1::2]",
"input": "f('abcdefg')",
"language": "Python",
"predicted_output": "('aceg', 'bdf')"
} |
cmso86qna00av6zp2dqeifczh | Submission EIFCZH | {
"code": "def f(xs):\n return all(a<=b for a,b in zip(xs,xs[1:]))",
"input": "f([1,1,3,2])",
"language": "Python",
"predicted_output": "False"
} |
cmso86qna00aw6zp2r24f0blp | Submission 4F0BLP | {
"code": "def f(xs):\n return sorted(set(xs), reverse=True)[1]",
"input": "f([4,1,4,3,2])",
"language": "Python",
"predicted_output": "3"
} |
cmso86qna00ax6zp2tv6a5vwz | Submission 6A5VWZ | {
"code": "def f(s):\n from collections import Counter\n return Counter(s).most_common(2)",
"input": "f('mississippi')",
"language": "Python",
"predicted_output": "[('i', 4), ('s', 4)]"
} |
cmso86qna00ay6zp2l56j8bab | Submission 6J8BAB | {
"code": "def f(x):\n try:return 100//x\n except ZeroDivisionError:return None",
"input": "(f(4),f(0))",
"language": "Python",
"predicted_output": "(25, None)"
} |
cmso86qna00az6zp2lezxzmbm | Submission ZXZMBM | {
"code": "def f(xs):\n return {x:i for i,x in enumerate(xs)}",
"input": "f(['a','b','a'])",
"language": "Python",
"predicted_output": "{'a': 2, 'b': 1}"
} |
cmso86qna00b06zp2zd2n1ugx | Submission 2N1UGX | {
"code": "def f(n):\n return [i for i in range(n) if all(i%d for d in range(2,int(i**.5)+1)) and i>1]",
"input": "f(12)",
"language": "Python",
"predicted_output": "[2, 3, 5, 7, 11]"
} |
cmso86qna00b16zp274gz4vu3 | Submission GZ4VU3 | {
"code": "def f(rows):\n return list(map(list,zip(*rows)))",
"input": "f([[1,2,3],[4,5,6]])",
"language": "Python",
"predicted_output": "[[1, 4], [2, 5], [3, 6]]"
} |
cmso86qna00b36zp2amh9wsg9 | Submission H9WSG9 | {
"code": "def f(xs):\n return [x for x in xs if xs.count(x)==1]",
"input": "f([1,2,1,3,4,3])",
"language": "Python",
"predicted_output": "[2, 4]"
} |
cmso86qna00b46zp2vsn4gdtl | Submission N4GDTL | {
"code": "def f(n):\n return divmod(n,60)",
"input": "f(367)",
"language": "Python",
"predicted_output": "(6, 7)"
} |
cmso86qna00b56zp2fjgg13to | Submission GG13TO | {
"code": "def f(xs):\n return min(xs,key=lambda x:(abs(x),x))",
"input": "f([-3,2,-2,5])",
"language": "Python",
"predicted_output": "-2"
} |
cmso86qna00b66zp2fsd9xno7 | Submission D9XNO7 | {
"code": "def f(s):\n return [p for p in s.split(',') if p]",
"input": "f('a,,b,c,')",
"language": "Python",
"predicted_output": "['a', 'b', 'c']"
} |
cmso86qna00b76zp2diwyb3st | Submission WYB3ST | {
"code": "def f(xs):\n return sum(x<0 for x in xs),sum(x==0 for x in xs),sum(x>0 for x in xs)",
"input": "f([-2,0,3,4,0])",
"language": "Python",
"predicted_output": "(1, 2, 2)"
} |
cmso86qna00b86zp2eyxxg698 | Submission XXG698 | {
"code": "def f(a,b):\n return sorted(set(a)&set(b))",
"input": "f([1,2,3,3],[2,3,4])",
"language": "Python",
"predicted_output": "[2, 3]"
} |
cmso86qna00b96zp2ri7k951l | Submission 7K951L | {
"code": "def f(xs,k):\n return [xs[i:i+k] for i in range(0,len(xs),k)]",
"input": "f([1,2,3,4,5],2)",
"language": "Python",
"predicted_output": "[[1, 2], [3, 4], [5]]"
} |
cmso86qna00ba6zp25nlwkblx | Submission LWKBLX | {
"code": "def f(d):\n return sum(v for k,v in d.items() if k.startswith('x'))",
"input": "f({'x1':3,'y':8,'x2':4})",
"language": "Python",
"predicted_output": "7"
} |
cmso86qna00bb6zp2czvyle8c | Submission VYLE8C | {
"code": "def f(s):\n return s == s[::-1]",
"input": "(f('level'),f('levels'))",
"language": "Python",
"predicted_output": "(True, False)"
} |
cmso86qna00bc6zp2s6gkvemp | Submission GKVEMP | {
"code": "def f(xs):\n return [b-a for a,b in zip(xs,xs[1:])]",
"input": "f([3,8,6,10])",
"language": "Python",
"predicted_output": "[5, -2, 4]"
} |
cmsoiw6wv0002ctp2qii51bdk | Submission I51BDK | {
"code": "def word_freq(text):\n freq = {}\n for w in text.split():\n freq[w] = freq.get(w, 0) + 1\n return sorted(freq.items())",
"input": "word_freq('a b a c b a')",
"language": "Python",
"predicted_output": "[('a', 3), ('b', 2), ('c', 1)]"
} |
cmsoiw6wv0003ctp2zexklme7 | Submission XKLME7 | {
"code": "class Stack:\n def __init__(self):\n self.data = []\n def push(self, x):\n self.data.append(x)\n def pop(self):\n return self.data.pop()\n def peek(self):\n return self.data[-1]\n\ndef stack_ops():\n s = Stack()\n s.push(1)\n s.push(2)\n s.push(3)\n s.... |
cmsoiw6wv0004ctp2137s2ov4 | Submission 7S2OV4 | {
"code": "def merge_intervals(intervals):\n intervals = sorted(intervals)\n merged = []\n for start, end in intervals:\n if merged and start <= merged[-1][1]:\n merged[-1] = (merged[-1][0], max(merged[-1][1], end))\n else:\n merged.append((start, end))\n return merged"... |
cmsoiw6wv0006ctp21ozcdeu6 | Submission ZCDEU6 | {
"code": "def flatten(nested):\n result = []\n for item in nested:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result",
"input": "flatten([1, [2, 3, [4, 5]], 6, [7]])",
"language": "Python",
"predicted_output": ... |
cmsoiw6wv0007ctp2yoqjb9a9 | Submission QJB9A9 | {
"code": "def char_count_map(s):\n from collections import Counter\n c = Counter(s)\n return dict(sorted(c.items()))",
"input": "char_count_map('mississippi')",
"language": "Python",
"predicted_output": "{'i': 4, 'm': 1, 'p': 2, 's': 4}"
} |
cmsoiw6wv0008ctp2a4c6cx15 | Submission C6CX15 | {
"code": "def rotate_list(lst, k):\n if not lst:\n return lst\n k = k % len(lst)\n return lst[-k:] + lst[:-k]",
"input": "rotate_list([1,2,3,4,5], 2)",
"language": "Python",
"predicted_output": "[4, 5, 1, 2, 3]"
} |
cmsoiw6wv0009ctp2ipjsuyvx | Submission JSUYVX | {
"code": "def is_balanced(s):\n stack = []\n pairs = {')':'(', ']':'[', '}':'{'}\n for ch in s:\n if ch in '([{':\n stack.append(ch)\n elif ch in ')]}':\n if not stack or stack.pop() != pairs[ch]:\n return False\n return not stack",
"input": "is_balanc... |
cmsoiw6ww000actp2ew30hct5 | Submission 30HCT5 | {
"code": "def gen_squares(n):\n def sq():\n for i in range(n):\n yield i * i\n return list(sq())",
"input": "gen_squares(6)",
"language": "Python",
"predicted_output": "[0, 1, 4, 9, 16, 25]"
} |
cmsoiw6ww000bctp2xn6m0ifa | Submission 6M0IFA | {
"code": "def try_finally_demo():\n log = []\n try:\n log.append('try')\n raise ValueError('boom')\n except ValueError as e:\n log.append(f'except:{e}')\n finally:\n log.append('finally')\n return log",
"input": "try_finally_demo()",
"language": "Python",
"predicted_o... |
cmsoiw6ww000cctp22nmb1dqv | Submission MB1DQV | {
"code": "def matrix_transpose(m):\n return [list(row) for row in zip(*m)]",
"input": "matrix_transpose([[1,2,3],[4,5,6]])",
"language": "Python",
"predicted_output": "[[1, 4], [2, 5], [3, 6]]"
} |
cmsoiw6ww000dctp286q9j66z | Submission Q9J66Z | {
"code": "def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n lo = mid + 1\n else:\n hi = mid - 1\n return -1",
"input": "binary_se... |
cmsoiw6ww000ectp21o6izba3 | Submission 6IZBA3 | {
"code": "def default_dict_demo():\n from collections import defaultdict\n d = defaultdict(list)\n for k, v in [('a',1),('b',2),('a',3)]:\n d[k].append(v)\n return dict(d)",
"input": "default_dict_demo()",
"language": "Python",
"predicted_output": "{'a': [1, 3], 'b': [2]}"
} |
cmsoiw6ww000fctp2s7vmficn | Submission VMFICN | {
"code": "def slice_tricks(s):\n return (s[::-1], s[1:-1], s[::2])",
"input": "slice_tricks('abcdefgh')",
"language": "Python",
"predicted_output": "('hgfedcba', 'bcdefg', 'aceg')"
} |
cmsoiw6ww000gctp2bmubxfi2 | Submission UBXFI2 | {
"code": "def sum_with_default_arg(lst, acc=None):\n if acc is None:\n acc = []\n acc.append(sum(lst))\n return acc",
"input": "sum_with_default_arg([1,2,3])",
"language": "Python",
"predicted_output": "[6]"
} |
cmsoiw6ww000hctp291s78r9t | Submission S78R9T | {
"code": "def zip_longest_demo():\n from itertools import zip_longest\n return list(zip_longest([1,2,3], ['a','b'], fillvalue='X'))",
"input": "zip_longest_demo()",
"language": "Python",
"predicted_output": "[(1, 'a'), (2, 'b'), (3, 'X')]"
} |
cmsoiw6ww000ictp2yf6ejk23 | Submission 6EJK23 | {
"code": "def recursive_factorial(n):\n if n <= 1:\n return 1\n return n * recursive_factorial(n - 1)",
"input": "recursive_factorial(6)",
"language": "Python",
"predicted_output": "720"
} |
cmsoiw6ww000jctp29v8o8zs4 | Submission 8O8ZS4 | {
"code": "def set_ops(a, b):\n sa, sb = set(a), set(b)\n return (sorted(sa & sb), sorted(sa | sb), sorted(sa - sb))",
"input": "set_ops([1,2,3,4], [3,4,5,6])",
"language": "Python",
"predicted_output": "([3, 4], [1, 2, 3, 4, 5, 6], [1, 2])"
} |
cmsoiw6ww000lctp2yyz7kppt | Submission Z7KPPT | {
"code": "def enumerate_demo(items):\n return [f'{i}:{v}' for i, v in enumerate(items, start=1)]",
"input": "enumerate_demo(['x','y','z'])",
"language": "Python",
"predicted_output": "['1:x', '2:y', '3:z']"
} |
cmsoiw6ww000mctp2lcd1lk4l | Submission D1LK4L | {
"code": "def list_comp_nested():\n return [[i*j for j in range(3)] for i in range(3)]",
"input": "list_comp_nested()",
"language": "Python",
"predicted_output": "[[0, 0, 0], [0, 1, 2], [0, 2, 4]]"
} |
cmsoiw6ww000octp2dhb2q6zr | Submission B2Q6ZR | {
"code": "def tuple_unpack_star(items):\n first, *middle, last = items\n return (first, middle, last)",
"input": "tuple_unpack_star([1,2,3,4,5])",
"language": "Python",
"predicted_output": "(1, [2, 3, 4], 5)"
} |
cmsoiw6ww000pctp2wuql4cqi | Submission QL4CQI | {
"code": "def while_else_demo(n):\n i = 2\n while i < n:\n if n % i == 0:\n return False\n i += 1\n else:\n return True",
"input": "while_else_demo(17)",
"language": "Python",
"predicted_output": "True"
} |
cmsoiw6ww000qctp2kqonlklt | Submission ONLKLT | {
"code": "def sorted_with_key(items):\n return sorted(items, key=lambda x: (-x[1], x[0]))",
"input": "sorted_with_key([('a',2),('b',3),('c',2)])",
"language": "Python",
"predicted_output": "[('b', 3), ('a', 2), ('c', 2)]"
} |
cmsoiw6ww000rctp2yfttzt5s | Submission TTZT5S | {
"code": "def nested_dict_update():\n d = {'a': {'x': 1}, 'b': {'y': 2}}\n d['a']['z'] = 99\n d.setdefault('c', {})['w'] = 5\n return d",
"input": "nested_dict_update()",
"language": "Python",
"predicted_output": "{'a': {'x': 1, 'z': 99}, 'b': {'y': 2}, 'c': {'w': 5}}"
} |
cmsoiw6ww000sctp23xzfrw36 | Submission ZFRW36 | {
"code": "def chained_comparison(a, b, c):\n return a < b < c",
"input": "chained_comparison(1, 5, 10)",
"language": "Python",
"predicted_output": "True"
} |
cmsoiw6ww000tctp23q7zs99g | Submission 7ZS99G | {
"code": "def bytes_ops():\n b = bytes([104, 101, 108, 108, 111])\n return (b, b.decode(), len(b))",
"input": "bytes_ops()",
"language": "Python",
"predicted_output": "(b'hello', 'hello', 5)"
} |
cmspwitjl000f7vp2s4nxh626 | Submission NXH626 | {
"code": "def fib_seq(n):\n cache = {0: 0, 1: 1}\n for i in range(2, n + 1):\n cache[i] = cache[i - 1] + cache[i - 2]\n return [cache[i] for i in range(n + 1)]",
"input": "fib_seq(7)",
"language": "Python",
"predicted_output": "[0, 1, 1, 2, 3, 5, 8, 13]"
} |
cmspwitjl000g7vp2wwlc5kvb | Submission LC5KVB | {
"code": "class ValidationError(Exception):\n pass\n\ndef validate_age(age):\n try:\n if age < 0:\n raise ValidationError(\"negative age\")\n return age * 2\n except ValidationError as e:\n return f\"error: {e}\"",
"input": "(validate_age(5), validate_age(-3))",
"language... |
cmspwitjl000h7vp2g6rrkp6v | Submission RRKP6V | {
"code": "def compare_sets(a, b):\n return {\n \"union\": sorted(a | b),\n \"intersection\": sorted(a & b),\n \"difference\": sorted(a - b)\n }",
"input": "compare_sets({1, 2, 3, 4}, {3, 4, 5})",
"language": "Python",
"predicted_output": "{'union': [1, 2, 3, 4, 5], 'intersection': [3... |
cmspwitjl000j7vp23qk98jyo | Submission K98JYO | {
"code": "def top_scores(records, n):\n return sorted(records, key=lambda r: (-r[1], r[0]))[:n]",
"input": "top_scores([(\"alice\", 90), (\"bob\", 95), (\"carol\", 90), (\"dave\", 95)], 3)",
"language": "Python",
"predicted_output": "[('bob', 95), ('dave', 95), ('alice', 90)]"
} |
cmspwitjl000k7vp2odtofi47 | Submission TOFI47 | {
"code": "def even_squares(nums):\n for n in nums:\n if n % 2 == 0:\n yield n * n\n\ndef sum_even_squares(nums):\n return sum(even_squares(nums))",
"input": "sum_even_squares([1, 2, 3, 4, 5, 6])",
"language": "Python",
"predicted_output": "56"
} |
cmspwitjl000l7vp22s6oyzqf | Submission 6OYZQF | {
"code": "def safe_factorial(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n if n == 0:\n return 1\n return n * safe_factorial(n - 1)\n\ndef try_factorial(n):\n try:\n return safe_factorial(n)\n except ValueError as e:\n return str(e)",
"input": "(try_fac... |
cmspwitjl000m7vp2rr3l0mcu | Submission 3L0MCU | {
"code": "def index_map(items):\n return {item: idx for idx, item in enumerate(items) if len(item) > 2}",
"input": "index_map([\"a\", \"cat\", \"dog\", \"it\", \"fish\"])",
"language": "Python",
"predicted_output": "{'cat': 1, 'dog': 2, 'fish': 4}"
} |
cmspwitjl000n7vp224dpj4xk | Submission DPJ4XK | {
"code": "def divide_safe(a, b):\n try:\n result = a / b\n except ZeroDivisionError:\n return \"cannot divide by zero\"\n except TypeError:\n return \"invalid types\"\n else:\n return round(result, 2)",
"input": "(divide_safe(10, 4), divide_safe(5, 0), divide_safe(5, \"x\"))... |
cmspwitjm000o7vp23dxlwsjg | Submission XLWSJG | {
"code": "def group_by_parity(nums):\n groups = {\"even\": [], \"odd\": []}\n for n in nums:\n key = \"even\" if n % 2 == 0 else \"odd\"\n groups[key].append(n)\n return groups",
"input": "group_by_parity([5, 8, 3, 12, 7, 2])",
"language": "Python",
"predicted_output": "{'even': [8, 12, ... |
cmsrbjijs001ze0p2jrqfx2y6 | Submission QFX2Y6 | {
"code": "def fib(n, memo=None):\n if memo is None:\n memo = {}\n if n <= 1:\n return n\n if n not in memo:\n memo[n] = fib(n - 1, memo) + fib(n - 2, memo)\n return memo[n]",
"input": "fib(10)",
"language": "Python",
"predicted_output": "55"
} |
cmsrbjijs0020e0p21tx642mr | Submission X642MR | {
"code": "def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n lo = mid + 1\n else:\n hi = mid - 1\n return -1",
"input": "binary_se... |
cmsrbjijs0021e0p22mfpiqi0 | Submission FPIQI0 | {
"code": "def transpose(matrix):\n return [list(row) for row in zip(*matrix)]",
"input": "transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9]])",
"language": "Python",
"predicted_output": "[[1, 4, 7], [2, 5, 8], [3, 6, 9]]"
} |
cmsrbjijs0022e0p2w1lkfihx | Submission LKFIHX | {
"code": "def word_frequency(text):\n words = text.lower().split()\n freq = {}\n for word in words:\n freq[word] = freq.get(word, 0) + 1\n return dict(sorted(freq.items()))",
"input": "word_frequency(\"to be or not to be that is the question\")",
"language": "Python",
"predicted_output": "{'... |
cmsrbjijs0023e0p2chvd1n9r | Submission VD1N9R | {
"code": "def flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result",
"input": "flatten([1, [2, [3, [4, 5]], 6], 7, [8, 9]])",
"language": "Python",
"predicted_output"... |
cmsrbjijs0024e0p21q7b2w9t | Submission 7B2W9T | {
"code": "def running_max(values):\n result = []\n current = float('-inf')\n for v in values:\n current = max(current, v)\n result.append(current)\n return result",
"input": "running_max([3, 1, 4, 1, 5, 9, 2, 6, 5])",
"language": "Python",
"predicted_output": "[3, 3, 4, 4, 5, 9, 9, 9,... |
cmsrbjijs0025e0p2xy76025p | Submission 76025P | {
"code": "def deep_merge(base, override):\n result = dict(base)\n for k, v in override.items():\n if k in result and isinstance(result[k], dict) and isinstance(v, dict):\n result[k] = deep_merge(result[k], v)\n else:\n result[k] = v\n return result",
"input": "deep_merg... |
cmsrbjijs0026e0p2jjnv7qve | Submission NV7QVE | {
"code": "def count_vowels_consonants(s):\n vowels = set('aeiouAEIOU')\n v_count = sum(1 for c in s if c in vowels)\n c_count = sum(1 for c in s if c.isalpha() and c not in vowels)\n return {'vowels': v_count, 'consonants': c_count}",
"input": "count_vowels_consonants(\"Hello World\")",
"language": "... |
cmsrbjijt0027e0p2xg3dj7hf | Submission 3DJ7HF | {
"code": "def rotate_list(lst, k):\n if not lst:\n return lst\n n = len(lst)\n k = k % n\n return lst[-k:] + lst[:-k] if k else list(lst)",
"input": "rotate_list([1, 2, 3, 4, 5, 6, 7], 3)",
"language": "Python",
"predicted_output": "[5, 6, 7, 1, 2, 3, 4]"
} |
cmsrbjijt0028e0p23f6xd9b6 | Submission 6XD9B6 | {
"code": "def rle_encode(s):\n if not s:\n return []\n result = []\n count = 1\n for i in range(1, len(s)):\n if s[i] == s[i - 1]:\n count += 1\n else:\n result.append((s[i - 1], count))\n count = 1\n result.append((s[-1], count))\n return resul... |
cmsrbjijt0029e0p2pggsig1c | Submission GSIG1C | {
"code": "def chunk_list(lst, size):\n return [lst[i:i + size] for i in range(0, len(lst), size)]",
"input": "chunk_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)",
"language": "Python",
"predicted_output": "[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]"
} |
cmsrbjijt002ae0p2hlzm00gj | Submission ZM00GJ | {
"code": "def are_anagrams(s1, s2):\n return sorted(s1.lower().replace(' ', '')) == sorted(s2.lower().replace(' ', ''))",
"input": "(are_anagrams(\"listen\", \"silent\"), are_anagrams(\"hello\", \"world\"))",
"language": "Python",
"predicted_output": "(True, False)"
} |
cmsrbjijt002be0p24nrygwj9 | Submission RYGWJ9 | {
"code": "def prime_factors(n):\n factors = []\n d = 2\n while d * d <= n:\n while n % d == 0:\n factors.append(d)\n n //= d\n d += 1\n if n > 1:\n factors.append(n)\n return factors",
"input": "prime_factors(360)",
"language": "Python",
"predicted_outp... |
cmsrbjijt002ce0p2gajtgfln | Submission JTGFLN | {
"code": "from collections import OrderedDict\n\nclass LRUCache:\n def __init__(self, capacity):\n self.capacity = capacity\n self.cache = OrderedDict()\n\n def get(self, key):\n if key not in self.cache:\n return -1\n self.cache.move_to_end(key)\n return self.cach... |
cmsrbjijt002de0p20ts6p8zm | Submission S6P8ZM | {
"code": "def zip_with_fill(list1, list2, fill=None):\n length = max(len(list1), len(list2))\n result = []\n for i in range(length):\n a = list1[i] if i < len(list1) else fill\n b = list2[i] if i < len(list2) else fill\n result.append((a, b))\n return result",
"input": "zip_with_fi... |
cmsrbjijt002ee0p2f5yni7f2 | Submission YNI7F2 | {
"code": "def cumsum_until(values, threshold):\n total = 0\n result = []\n for v in values:\n total += v\n result.append(total)\n if total >= threshold:\n break\n return result",
"input": "cumsum_until([5, 3, 8, 2, 7, 4], 20)",
"language": "Python",
"predicted_output... |
cmsrbjijt002ge0p2bo2wdgr5 | Submission 2WDGR5 | {
"code": "def merge_sorted(arr1, arr2):\n result = []\n i = j = 0\n while i < len(arr1) and j < len(arr2):\n if arr1[i] <= arr2[j]:\n result.append(arr1[i])\n i += 1\n else:\n result.append(arr2[j])\n j += 1\n result.extend(arr1[i:])\n result.e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.