task_id
int64
19.3k
41.9M
prompt
stringlengths
17
68
suffix
stringlengths
0
22
canonical_solution
stringlengths
6
153
test_start
stringlengths
22
198
test
sequence
entry_point
stringlengths
7
10
intent
stringlengths
19
200
library
sequence
38,388,799
def f_38388799(list_of_strings): return
sorted(list_of_strings, key=lambda s: s.split(',')[1])
def check(candidate):
[ "\n assert candidate(['parrot, medicine', 'abott, kangaroo', 'sriracha, coriander', 'phone, bottle']) == ['phone, bottle', 'sriracha, coriander', 'abott, kangaroo', 'parrot, medicine']\n", "\n assert candidate(['abott, kangaroo', 'parrot, medicine', 'sriracha, coriander', 'phone, bottle']) == ['phone, bottle', 'sriracha, coriander', 'abott, kangaroo', 'parrot, medicine']\n" ]
f_38388799
sort list `list_of_strings` based on second index of each string `s`
[]
37,004,138
def f_37004138(lst): return
[element for element in lst if isinstance(element, int)]
def check(candidate):
[ "\n lst = [1, \"hello\", \"string\", 2, 4.46]\n assert candidate(lst) == [1, 2]\n", "\n lst = [\"hello\", \"string\"]\n assert candidate(lst) == []\n" ]
f_37004138
eliminate non-integer items from list `lst`
[]
37,004,138
def f_37004138(lst): return
[element for element in lst if not isinstance(element, str)]
def check(candidate):
[ "\n lst = [1, \"hello\", \"string\", 2, 4.46]\n assert candidate(lst) == [1, 2, 4.46]\n", "\n lst = [\"hello\", \"string\"]\n assert candidate(lst) == []\n" ]
f_37004138
get all the elements except strings from the list 'lst'.
[]
72,899
def f_72899(list_to_be_sorted): return
sorted(list_to_be_sorted, key=lambda k: k['name'])
def check(candidate):
[ "\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD'}, {'name': 'ABCD'}]\n" ]
f_72899
Sort a list of dictionaries `list_to_be_sorted` by the value of the dictionary key `name`
[]
72,899
def f_72899(l): return
sorted(l, key=itemgetter('name'), reverse=True)
from operator import itemgetter def check(candidate):
[ "\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'ABCD'}, {'name': 'AABCD'}]\n" ]
f_72899
sort a list of dictionaries `l` by values in key `name` in descending order
[ "operator" ]
72,899
def f_72899(list_of_dicts):
return list_of_dicts
list_of_dicts.sort(key=operator.itemgetter('name'))
import operator def check(candidate):
[ "\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD'}, {'name': 'ABCD'}]\n" ]
f_72899
sort a list of dictionaries `list_of_dicts` by `name` values of the dictionary
[ "operator" ]
72,899
def f_72899(list_of_dicts):
return list_of_dicts
list_of_dicts.sort(key=operator.itemgetter('age'))
import operator def check(candidate):
[ "\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD', 'age': 10}, {'name': 'AABCD', 'age': 9}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD', 'age': 9}, {'name': 'ABCD', 'age': 10}]\n" ]
f_72899
sort a list of dictionaries `list_of_dicts` by `age` values of the dictionary
[ "operator" ]
36,402,748
def f_36402748(df): return
df.groupby('prots').sum().sort_values('scores', ascending=False)
import pandas as pd def check(candidate):
[ "\n COLUMN_NAMES = [\"chemicals\", \"prots\", \"scores\"]\n data = [[\"chemical1\", \"prot1\", 100],[\"chemical2\", \"prot2\", 50],[\"chemical3\", \"prot1\", 120]]\n df = pd.DataFrame(data, columns = COLUMN_NAMES)\n assert candidate(df).to_dict() == {'scores': {'prot1': 220, 'prot2': 50}}\n" ]
f_36402748
sort a Dataframe `df` by the total ocurrences in a column 'scores' group by 'prots'
[ "pandas" ]
29,881,993
def f_29881993(trans): return
""",""".join(trans['category'])
def check(candidate):
[ "\n trans = {'category':[\"hello\", \"world\",\"test\"], 'dummy_key':[\"dummy_val\"]}\n assert candidate(trans) == \"hello,world,test\"\n" ]
f_29881993
join together with "," elements inside a list indexed with 'category' within a dictionary `trans`
[]
34,158,494
def f_34158494(): return
"""""".join(['A', 'B', 'C', 'D'])
def check(candidate):
[ "\n assert candidate() == 'ABCD'\n" ]
f_34158494
concatenate array of strings `['A', 'B', 'C', 'D']` into a string
[]
12,666,897
def f_12666897(sents): return
[x for x in sents if not x.startswith('@$\t') and not x.startswith('#')]
def check(candidate):
[ "\n sents = [\"@$\tabcd\", \"#453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"abcd\", \"hello\", \"1\"]\n", "\n sents = [\"@$\tabcd\", \"@$t453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"@$t453923\", \"abcd\", \"hello\", \"1\"]\n", "\n sents = [\"#tabcd\", \"##453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"abcd\", \"hello\", \"1\"] \n" ]
f_12666897
Remove all strings from a list a strings `sents` where the values starts with `@$\t` or `#`
[]
5,944,630
def f_5944630(list):
return list
list.sort(key=lambda item: (item['points'], item['time']))
def check(candidate):
[ "\n list = [\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':50,'time': '0:03:00'},\n {'name':'TEST','points':20,'time': '0:03:00'}\n ]\n assert candidate(list) == [\n {'name':'TEST','points':20,'time': '0:03:00'}, \n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':50,'time': '0:03:00'}\n ]\n", "\n list = [\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':30,'time': '0:03:00'},\n {'name':'TEST','points':30,'time': '0:01:01'}\n ]\n assert candidate(list) == [\n {'name':'TEST','points':30,'time': '0:01:01'},\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':30,'time': '0:03:00'}\n ]\n" ]
f_5944630
sort a list of dictionary `list` first by key `points` and then by `time`
[]
7,852,855
def f_7852855(): return
datetime.datetime(1970, 1, 1).second
import time import datetime def check(candidate):
[ "\n assert candidate() == 0\n" ]
f_7852855
convert datetime object `(1970, 1, 1)` to seconds
[ "datetime", "time" ]
2,763,750
def f_2763750(): return
re.sub('(\\_a)?\\.([^\\.]*)$', '_suff.\\2', 'long.file.name.jpg')
import re def check(candidate):
[ "\n assert candidate() == 'long.file.name_suff.jpg'\n" ]
f_2763750
insert `_suff` before the file extension in `long.file.name.jpg` or replace `_a` with `suff` if it precedes the extension.
[ "re" ]
6,420,361
def f_6420361(module):
return
imp.reload(module)
import imp from unittest.mock import Mock def check(candidate):
[ "\n imp.reload = Mock()\n try:\n candidate('ads')\n assert True\n except:\n assert False\n" ]
f_6420361
reload a module `module`
[ "imp" ]
19,546,911
def f_19546911(number): return
struct.unpack('H', struct.pack('h', number))
import struct def check(candidate):
[ "\n assert candidate(3) == (3,)\n" ]
f_19546911
Convert integer `number` into an unassigned integer
[ "struct" ]
9,746,522
def f_9746522(numlist):
return numlist
numlist = [float(x) for x in numlist]
def check(candidate):
[ "\n assert candidate([3, 4]) == [3.0, 4.0]\n" ]
f_9746522
convert int values in list `numlist` to float
[]
20,107,570
def f_20107570(df, filename):
return
df.to_csv(filename, index=False)
import pandas as pd def check(candidate):
[ "\n file_name = 'a.csv'\n df = pd.DataFrame([1, 2, 3], columns = ['Vals'])\n candidate(df, file_name)\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert len(lines) == 4\n" ]
f_20107570
write dataframe `df`, excluding index, to a csv file `filename`
[ "pandas" ]
8,740,353
def f_8740353(unescaped):
return json_data
json_data = json.loads(unescaped)
import json def check(candidate):
[ "\n x = \"\"\"{\n \"Name\": \"Jennifer Smith\",\n \"Contact Number\": 7867567898,\n \"Email\": \"jen123@gmail.com\",\n \"Hobbies\":[\"Reading\", \"Sketching\", \"Horse Riding\"]\n }\"\"\"\n assert candidate(x) == {'Hobbies': ['Reading', 'Sketching', 'Horse Riding'], 'Name': 'Jennifer Smith', 'Email': 'jen123@gmail.com', 'Contact Number': 7867567898}\n" ]
f_8740353
convert a urllib unquoted string `unescaped` to a json data `json_data`
[ "json" ]
5,891,453
def f_5891453(): return
[chr(i) for i in range(127)]
def check(candidate):
[ "\n chars = candidate()\n assert len(chars) == 127\n assert chars == [chr(i) for i in range(127)]\n" ]
f_5891453
Create a list containing all ascii characters as its elements
[]
18,367,007
def f_18367007(newFileBytes, newFile):
return
newFile.write(struct.pack('5B', *newFileBytes))
import struct def check(candidate):
[ "\n newFileBytes = [123, 3, 123, 100, 99]\n file_name = 'f.txt'\n newFile = open(file_name, 'wb')\n candidate(newFileBytes, newFile)\n newFile.close()\n with open (file_name, 'rb') as f:\n lines = f.readlines()\n assert lines == [b'{\u0003{dc']\n" ]
f_18367007
write `newFileBytes` to a binary file `newFile`
[ "struct" ]
21,805,490
def f_21805490(string): return
re.sub('^[A-Z0-9]*(?![a-z])', '', string)
import re def check(candidate):
[ "\n assert candidate(\"AASKH317298DIUANFProgramming is fun\") == \"Programming is fun\"\n" ]
f_21805490
python regex - check for a capital letter with a following lowercase in string `string`
[ "re" ]
16,125,229
def f_16125229(dict): return
list(dict.keys())[-1]
def check(candidate):
[ "\n assert candidate({'t': 1, 'r': 2}) == 'r'\n", "\n assert candidate({'c': 1, 'b': 2, 'a': 1}) == 'a'\n" ]
f_16125229
get the last key of dictionary `dict`
[]
6,159,900
def f_6159900(f): return
print('hi there', file=f)
def check(candidate):
[ "\n file_name = 'a.txt'\n f = open(file_name, 'w')\n candidate(f)\n f.close()\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'hi there\\n'\n" ]
f_6159900
write line "hi there" to file `f`
[]
6,159,900
def f_6159900(myfile):
return
f = open(myfile, 'w') f.write("hi there\n") f.close()
def check(candidate):
[ "\n file_name = 'myfile'\n candidate(file_name)\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'hi there\\n'\n" ]
f_6159900
write line "hi there" to file `myfile`
[]
6,159,900
def f_6159900():
return
with open('somefile.txt', 'a') as the_file: the_file.write('Hello\n')
def check(candidate):
[ "\n file_name = 'somefile.txt'\n candidate()\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'Hello\\n'\n" ]
f_6159900
write line "Hello" to file `somefile.txt`
[]
19,527,279
def f_19527279(s): return
s.encode('iso-8859-15')
def check(candidate):
[ "\n assert candidate('table') == b'table'\n", "\n assert candidate('hello world!') == b'hello world!'\n" ]
f_19527279
convert unicode string `s` to ascii
[]
356,483
def f_356483(text): return
re.findall('Test([0-9.]*[0-9]+)', text)
import re def check(candidate):
[ "\n assert candidate('Test0.9ssd') == ['0.9']\n", "\n assert candidate('Test0.0 ..2ssd') == ['0.0']\n" ]
f_356483
Find all numbers and dots from a string `text` using regex
[ "re" ]
38,081,866
def f_38081866(): return
os.system('powershell.exe', 'script.ps1')
import os from unittest.mock import Mock def check(candidate):
[ "\n os.system = Mock()\n try:\n candidate()\n assert True\n except:\n assert False\n" ]
f_38081866
execute script 'script.ps1' using 'powershell.exe' shell
[ "os" ]
7,349,646
def f_7349646(b):
return b
b.sort(key=lambda x: x[2])
def check(candidate):
[ "\n b = [(1,2,3), (4,5,6), (7,8,0)]\n assert candidate(b) == [(7,8,0), (1,2,3), (4,5,6)]\n", "\n b = [(1,2,'a'), (4,5,'c'), (7,8,'A')]\n assert candidate(b) == [(7,8,'A'), (1,2,'a'), (4,5,'c')]\n" ]
f_7349646
Sort a list of tuples `b` by third item in the tuple
[]
10,607,688
def f_10607688(): return
datetime.datetime.now()
import datetime def check(candidate):
[ "\n y = candidate()\n assert y.year >= 2022\n" ]
f_10607688
create a datetime with the current date & time
[ "datetime" ]
30,843,103
def f_30843103(lst): return
next(i for i, x in enumerate(lst) if not isinstance(x, bool) and x == 1)
def check(candidate):
[ "\n lst = [True, False, 1, 3]\n assert candidate(lst) == 2\n" ]
f_30843103
get the index of an integer `1` from a list `lst` if the list also contains boolean items
[]
4,918,425
def f_4918425(a):
return a
a[:] = [(x - 13) for x in a]
def check(candidate):
[ "\n a = [14, 15]\n candidate(a)\n assert a == [1, 2]\n", "\n a = [float(x) for x in range(13, 20)]\n candidate(a)\n assert a == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]\n" ]
f_4918425
subtract 13 from every number in a list `a`
[]
17,794,266
def f_17794266(x): return
max(x.min(), x.max(), key=abs)
import numpy as np def check(candidate):
[ "\n x = np.matrix([[1, 1], [2, -3]])\n assert candidate(x) == -3\n" ]
f_17794266
get the highest element in absolute value in a numpy matrix `x`
[ "numpy" ]
30,551,576
def f_30551576(s): return
re.findall(r'"(http.*?)"', s, re.MULTILINE | re.DOTALL)
import re def check(candidate):
[ "\n s = (\n ' [irrelevant javascript code here]'\n ' sources:[{file:\"http://url.com/folder1/v.html\",label:\"label1\"},'\n ' {file:\"http://url.com/folder2/v.html\",label:\"label2\"},'\n ' {file:\"http://url.com/folder3/v.html\",label:\"label3\"}],'\n ' [irrelevant javascript code here]'\n )\n assert candidate(s) == ['http://url.com/folder1/v.html', 'http://url.com/folder2/v.html', 'http://url.com/folder3/v.html']\n", "\n s = (\n ' [irrelevant javascript code here]'\n ' [irrelevant python code here]'\n )\n assert candidate(s) == []\n" ]
f_30551576
Get all urls within text `s`
[ "re" ]
113,534
def f_113534(mystring): return
mystring.replace(' ', '! !').split('!')
def check(candidate):
[ "\n assert candidate(\"This is the string I want to split\") == ['This',' ','is',' ','the',' ','string',' ','I',' ','want',' ','to',' ','split']\n" ]
f_113534
split a string `mystring` considering the spaces ' '
[]
5,838,735
def f_5838735(path): return
open(path, 'r')
def check(candidate):
[ "\n with open('tmp.txt', 'w') as fw: fw.write('hello world!')\n f = candidate('tmp.txt')\n assert f.name == 'tmp.txt'\n assert f.mode == 'r'\n" ]
f_5838735
open file `path` with mode 'r'
[]
36,003,967
def f_36003967(data): return
[[sum(item) for item in zip(*items)] for items in zip(*data)]
def check(candidate):
[ "\n data = [[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]],\n [[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]],\n [[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]]\n assert candidate(data) == [[54, 40, 50, 50, 200], [20, 30, 75, 90, 180]]\n" ]
f_36003967
sum elements at the same index in list `data`
[]
7,635,237
def f_7635237(a): return
a[:, (np.newaxis)]
import numpy as np def check(candidate):
[ "\n data = np.array([[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]],\n [[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]],\n [[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]])\n assert candidate(data).tolist() == [[[[ 5, 10, 30, 24, 100],\n [ 1, 9, 25, 49, 81]]],\n [[[ 15, 10, 10, 16, 70],\n [ 10, 1, 25, 11, 19]]],\n [[[ 34, 20, 10, 10, 30],\n [ 9, 20, 25, 30, 80]]]]\n" ]
f_7635237
add a new axis to array `a`
[ "numpy" ]