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
sequencelengths
1
7
entry_point
stringlengths
7
10
intent
stringlengths
19
200
library
sequencelengths
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, 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" ]
[ { "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 = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]). Equivalent to: def itemgetter(*items):", "title": "python.library.operator#operator.itemgetter" } ]
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" ]
[ { "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 = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]). Equivalent to: def itemgetter(*items):", "title": "python.library.operator#operator.itemgetter" } ]
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" ]
[ { "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 = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]). Equivalent to: def itemgetter(*items):", "title": "python.library.operator#operator.itemgetter" } ]
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 operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups. Parameters ", "title": "pandas.reference.api.pandas.dataframe.groupby" }, { "function": "dataframe.sort_values", "text": "pandas.DataFrame.sort_values DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)[source]\n \nSort by the values along either axis. Parameters ", "title": "pandas.reference.api.pandas.dataframe.sort_values" } ]
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" ]
[ { "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 following ranges: \nMINYEAR <= year <= MAXYEAR, \n1 <= month <= 12, \n1 <= day <= number of days in the given month and year, \n0 <= hour < 24, \n0 <= minute < 60, \n0 <= second < 60, \n0 <= microsecond < 1000000, \nfold in [0, 1]. If an argument outside those ranges is given, ValueError is raised. New in version 3.6: Added the fold argument.", "title": "python.library.datetime#datetime.datetime" } ]
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 it is a string, any backslash escapes in it are processed. That is, \\n is converted to a single newline character, \\r is converted to a carriage return, and so forth. Unknown escapes of ASCII letters are reserved for future use and treated as errors. Other unknown escapes such as \\& are left alone. Backreferences, such as \\6, are replaced with the substring matched by group 6 in the pattern. For example: >>> re.sub(r'def\\s+([a-zA-Z_][a-zA-Z_0-9]*)\\s*\\(\\s*\\):',\n... r'static PyObject*\\npy_\\1(void)\\n{',\n... 'def myfunc():')\n'static PyObject*\\npy_myfunc(void)\\n{'\n If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string. For example: >>> def dashrepl(matchobj):\n... if matchobj.group(0) == '-': return ' '\n... else: return '-'", "title": "python.library.re#re.sub" } ]
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 without leaving the Python interpreter. The return value is the module object (which can be different if re-importing causes a different object to be placed in sys.modules). When reload() is executed: Python module’s code is recompiled and the module-level code re-executed, defining a new set of objects which are bound to names in the module’s dictionary by reusing the loader which originally loaded the module. The init function of extension modules is not called a second time. As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero. The names in the module namespace are updated to point to any new or changed objects. Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired. There are a number of other caveats: When a module is reloaded, its dictionary (containing the module’s global variables) is retained. Redefinitions of names will override the old definitions, so this is generally not a problem. If the new version of a module does not define a name that was defined by the old version, the old definition remains. This feature can be used to the module’s advantage if it maintains a global table or cache of objects — with a try statement it can test for the table’s presence and skip its initialization if desired: try:\n cache\nexcept NameError:\n cache = {}\n It is generally not very useful to reload built-in or dynamically loaded modules. Reloading sys, __main__, builtins and other key modules is not recommended. In many cases extension modules are not designed to be initialized more than once, and may fail in arbitrary ways when reloaded. If a module imports objects from another module using from … import …, calling reload() for the other module does not redefine the objects imported from it — one way around this is to re-execute the from statement, another is to use import and qualified names (module.name) instead. If a module instantiates instances of a class, reloading the module that defines the class does not affect the method definitions of the instances — they continue to use the old class definition. The same is true for derived classes. New in version 3.4. Changed in version 3.7: ModuleNotFoundError is raised when the module being reloaded lacks a ModuleSpec.", "title": "python.library.importlib#importlib.reload" } ]
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 format, as reflected by calcsize().", "title": "python.library.struct#struct.unpack" } ]
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, date_format=None, doublequote=True, escapechar=None, decimal='.', errors='strict', storage_options=None)[source]\n \nWrite object to a comma-separated values (csv) file. Parameters ", "title": "pandas.reference.api.pandas.dataframe.to_csv" } ]
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" ]
[ { "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 arguments have the same meaning as in load(). If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised. Changed in version 3.6: s can now be of type bytes or bytearray. The input encoding should be UTF-8, UTF-16 or UTF-32. Changed in version 3.9: The keyword argument encoding has been removed.", "title": "python.library.json#json.loads" } ]
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 it is a string, any backslash escapes in it are processed. That is, \\n is converted to a single newline character, \\r is converted to a carriage return, and so forth. Unknown escapes of ASCII letters are reserved for future use and treated as errors. Other unknown escapes such as \\& are left alone. Backreferences, such as \\6, are replaced with the substring matched by group 6 in the pattern. For example: >>> re.sub(r'def\\s+([a-zA-Z_][a-zA-Z_0-9]*)\\s*\\(\\s*\\):',\n... r'static PyObject*\\npy_\\1(void)\\n{',\n... 'def myfunc():')\n'static PyObject*\\npy_myfunc(void)\\n{'\n If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string. For example: >>> def dashrepl(matchobj):\n... if matchobj.group(0) == '-': return ' '\n... else: return '-'", "title": "python.library.re#re.sub" } ]
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 groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result. Changed in version 3.7: Non-empty matches can now start just after a previous empty match.", "title": "python.library.re#re.findall" } ]
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 any output, it will be sent to the interpreter standard output stream. On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent. On Windows, the return value is that returned by the system shell after running command. The shell is given by the Windows environment variable COMSPEC: it is usually cmd.exe, which returns the exit status of the command run; on systems using a non-native shell, consult your shell documentation. The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes. On Unix, waitstatus_to_exitcode() can be used to convert the result (exit status) into an exit code. On Windows, the result is directly the exit code. Raises an auditing event os.system with argument command. Availability: Unix, Windows.", "title": "python.library.os#os.system" } ]
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, this may be possible on platforms supplying the C gettimeofday() function). If tz is not None, it must be an instance of a tzinfo subclass, and the current date and time are converted to tz’s time zone. This function is preferred over today() and utcnow().", "title": "python.library.datetime#datetime.datetime.now" } ]
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.generated.numpy.ndarray.max" } ]
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" ]
[ { "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 groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result. Changed in version 3.7: Non-empty matches can now start just after a previous empty match.", "title": "python.library.re#re.findall" } ]
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" ]
[ { "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" } ]