task_id int64 19.3k 41.9M | prompt stringlengths 17 68 | suffix stringclasses 37 values | canonical_solution stringlengths 6 153 | test_start stringlengths 22 198 | test listlengths 1 7 | entry_point stringlengths 7 10 | intent stringlengths 19 200 | library listlengths 0 3 | docs listlengths 0 3 |
|---|---|---|---|---|---|---|---|---|---|
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, bottl... | 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': ... | 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': ... | f_72899 | sort a list of dictionaries `l` by values in key `name` in descending order | [
"operator"
] | [
{
"function": "operator.itemgetter",
"text": "operator.itemgetter(item) \noperator.itemgetter(*items) \nReturn a callable object that fetches item from its operand using the operand’s __getitem__() method. If multiple items are specified, returns a tuple of lookup values. For example: After f = itemgette... | |
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': ... | f_72899 | sort a list of dictionaries `list_of_dicts` by `name` values of the dictionary | [
"operator"
] | [
{
"function": "operator.itemgetter",
"text": "operator.itemgetter(item) \noperator.itemgetter(*items) \nReturn a callable object that fetches item from its operand using the operand’s __getitem__() method. If multiple items are specified, returns a tuple of lookup values. For example: After f = itemgette... |
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_... | f_72899 | sort a list of dictionaries `list_of_dicts` by `age` values of the dictionary | [
"operator"
] | [
{
"function": "operator.itemgetter",
"text": "operator.itemgetter(item) \noperator.itemgetter(*items) \nReturn a callable object that fetches item from its operand using the operand’s __getitem__() method. If multiple items are specified, returns a tuple of lookup values. For example: After f = itemgette... |
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"
] | [
{
"function": "dataframe.groupby",
"text": "pandas.DataFrame.groupby DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=NoDefault.no_default, observed=False, dropna=True)[source]\n \nGroup DataFrame using a mapper or by a Series of columns. A groupby operatio... | |
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 = [\"#tabc... | 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... | 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"
] | [
{
"function": "datetime.datetime",
"text": "class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0) \nThe year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments must be integers in the... | |
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"
] | [
{
"function": "re.sub",
"text": "re.sub(pattern, repl, string, count=0, flags=0) \nReturn the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if ... | |
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"
] | [
{
"function": "imp.reload",
"text": "importlib.reload(module) \nReload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version... |
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"
] | [
{
"function": "struct.unpack",
"text": "struct.unpack(format, buffer) \nUnpack from the buffer buffer (presumably packed by pack(format, ...)) according to the format string format. The result is a tuple even if it contains exactly one item. The buffer’s size in bytes must match the size required by the fo... | |
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"
] | [
{
"function": "df.to_csv",
"text": "pandas.DataFrame.to_csv DataFrame.to_csv(path_or_buf=None, sep=',', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, mode='w', encoding=None, compression='infer', quoting=None, quotechar='\"', line_terminator=None, chunksize=None, d... |
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', 'E... | f_8740353 | convert a urllib unquoted string `unescaped` to a json data `json_data` | [
"json"
] | [
{
"function": "json.loads",
"text": "json.loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) \nDeserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object using this conversion table. The other ar... |
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"
] | [
{
"function": "struct.pack",
"text": "struct.pack(format, v1, v2, ...) \nReturn a bytes object containing the values v1, v2, … packed according to the format string format. The arguments must match the values required by the format exactly.",
"title": "python.library.struct#struct.pack"
}
] |
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"
] | [
{
"function": "re.sub",
"text": "re.sub(pattern, repl, string, count=0, flags=0) \nReturn the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if ... | |
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"
] | [
{
"function": "re.findall",
"text": "re.findall(pattern, string, flags=0) \nReturn all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of gro... | |
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"
] | [
{
"function": "os.system",
"text": "os.system(command) \nExecute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same limitations. Changes to sys.stdin, etc. are not reflected in the environment of the executed command. If command generates... | |
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"
] | [
{
"function": "datetime.now",
"text": "classmethod datetime.now(tz=None) \nReturn the current local date and time. If optional argument tz is None or not specified, this is like today(), but, if possible, supplies more precision than can be gotten from going through a time.time() timestamp (for example, th... | |
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"
] | [
{
"function": "max",
"text": "numpy.ndarray.max method ndarray.max(axis=None, out=None, keepdims=False, initial=<no value>, where=True)\n \nReturn the maximum along a given axis. Refer to numpy.amax for full documentation. See also numpy.amax\n\nequivalent function",
"title": "numpy.reference.genera... | |
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 j... | f_30551576 | Get all urls within text `s` | [
"re"
] | [
{
"function": "re.findall",
"text": "re.findall(pattern, string, flags=0) \nReturn all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of gro... | |
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, ... | f_7635237 | add a new axis to array `a` | [
"numpy"
] | [
{
"function": "numpy.newaxis",
"text": "numpy.newaxis\n \nA convenient alias for None, useful for indexing arrays. Examples >>> newaxis is None\nTrue",
"title": "numpy.reference.constants#numpy.newaxis"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.