{"task_id": 54979, "prompt": "def f_54979(dic):\n\t", "suffix": "\n\treturn result", "canonical_solution": "result = defaultdict(list)\n\tfor d in dic.values():\n\t for k,v in d.items():\n\t result[k].append(v)", "test_start": "\nfrom collections import defaultdict\n\ndef check(candidate):", "test": ["\n dic = {'xx': {0: 0., 1: 1., 2: 2.}, 'yy': {1: '1', 2: '2'}, 'zz': {2: 2}}\n assert dict(candidate(dic)) == {0: [0.0], 1: [1.0, '1'], 2: [2.0, '2', 2]}\n"], "entry_point": "f_54979", "intent": "\u00bfC\u00f3mo obtener un dictionario `result` con las llaves `keys` y los valores `val` de un diccionario `dic`?", "library": ["collections"]} {"task_id": 39675, "prompt": "def f_39675(x, y):\n\t", "suffix": "\n\treturn sol", "canonical_solution": "\n\tdy = diff(y)\n\tsol = solve(dy)\n", "test_start": "\nfrom sympy import *\n\ndef check(candidate):", "test": ["\n x = symbols('x')\n y = -(x-0.4)**2+10\n assert candidate(x, y)[0] == 0.4\n"], "entry_point": "f_39675", "intent": "\u00bfC\u00f3mo encontrar el m\u00e1ximo de una funci\u00f3n `y` que depende de `x`?", "library": ["sympy"]} {"task_id": 19921, "prompt": "def f_19921(file, ruta):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\twith open(file, 'rb') as fsrc:\n\t\ta = fsrc.read()\n\tshutil.copyfile(file, ruta)\n", "test_start": "\nimport os\nimport shutil\n\ndef check(candidate):", "test": ["\n file = \"tmp.txt\"\n with open(file, 'w') as fw: \n fw.write(\"hello world!\")\n ruta = \"test/tmp.txt\"\n os.mkdir(\"test\")\n candidate(file, ruta)\n assert os.path.isfile(ruta) == True\n"], "entry_point": "f_19921", "intent": "\u00bfC\u00f3mo subir archivos a una carpeta local ubicada en `ruta` despu\u00e9s de abrirlo?", "library": ["os", "shutil"]} {"task_id": 25024, "prompt": "def f_25024(lst):\n\treturn ", "suffix": "", "canonical_solution": "list(sum(zip(lst, lst[1:]), ()))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4]) == [1,2,2,3,3,4]\n"], "entry_point": "f_25024", "intent": "\u00bfC\u00f3mo duplicar los elementos de una lista `lst` excluyendo los extremos?", "library": []} {"task_id": 774, "prompt": "def f_774():\n\t", "suffix": "\n\treturn C", "canonical_solution": "\n\tclass C:\n\t\tdef __init__(self):\n\t\t\tself.total_renombres = 0\n\n\t\tdef _incrementa_contador_renombres(self):\n\t\t\tself.total_renombres += 1\n", "test_start": "\ndef check(candidate):", "test": ["\n sample = candidate()()\n sample._incrementa_contador_renombres()\n assert sample.total_renombres == 1\n"], "entry_point": "f_774", "intent": "\u00bfC\u00f3mo contar las llamadas totales al m\u00e9todo de una clase `C`?", "library": []} {"task_id": 38658, "prompt": "def f_38658(img, x):\n\t", "suffix": "\n\treturn ", "canonical_solution": "im = Image.open(img)\n\tim.rotate(x).show()", "test_start": "\nfrom PIL import Image\n\ndef check(candidate):", "test": ["\n im = Image.new('RGBA', (200, 200), (255, 255, 255, 255))\n im.save('v.png')\n try:\n candidate('v.png', 45)\n except:\n assert False\n"], "entry_point": "f_38658", "intent": "\u00bfC\u00f3mo rotar una imagen `img` en un \u00e1ngulo de `x` grados en Tkinter?", "library": ["PIL"]} {"task_id": 49642, "prompt": "def f_49642(date):\n\t", "suffix": "\n\treturn mesANumero(date)", "canonical_solution": "\n\tdef mesANumero(date):\n\t m = {\n\t 'enero': '01',\n\t 'febrero': '02',\n\t 'marzo': '03',\n\t 'abril': '04',\n\t 'mayo': '05',\n\t 'junio': '06',\n\t 'julio': '07',\n\t 'agosto': '08',\n\t 'septiembre': '09',\n\t 'octubre': '10',\n\t 'noviembre': '11',\n\t 'diciembre': '12'\n\t }\n\t\n\t fecha = date.split('-')\n\t dia = fecha[0]\n\t mes = fecha[1]\n\t anio = fecha[2]\n\t\n\t try:\n\t out = str(m[mes.lower()])\n\t return dia + '-' + out + '-' + anio\n\t except:\n\t raise ValueError('No es un mes')\n\t\n", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('13-noviembre-2007') == '13-11-2007'\n"], "entry_point": "f_49642", "intent": "\u00bfC\u00f3mo transformar una fecha `date` en palabras a fecha en n\u00fameros?", "library": []} {"task_id": 2611, "prompt": "def f_2611():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.Popen('proc')", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.Popen = Mock()\n try:\n candidate()\n except:\n assert False\n"], "entry_point": "f_2611", "intent": "\u00bfC\u00f3mo crar un subproceso `proc`?", "library": ["subprocess"]} {"task_id": 71600, "prompt": "def f_71600(n, m):\n\t", "suffix": "\n\treturn array", "canonical_solution": "\n\tarray = []\n\tfor count in range(n):\n\t\trow = []\n\t\tfor count in range(m):\n\t\t\tm = matriz()\n\t\t\trow.append(m)\n\t\tarray.append(row)\n\n", "test_start": "\ndef matriz(): return 0\n\ndef check(candidate):", "test": ["\n e = candidate(2, 2)\n assert len(e) == 2\n assert len(e[0]) == 2\n"], "entry_point": "f_71600", "intent": "\u00bfC\u00f3mo crear una matriz `array` de `n`x`m` matrices?", "library": []} {"task_id": 37964, "prompt": "def f_37964(mi_lista):\n\treturn ", "suffix": "", "canonical_solution": "[(x,y) for x in mi_lista for y in mi_lista if x!=y]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([5, 6, 7, 8]) == [(5, 6), (5, 7), (5, 8), (6, 5), (6, 7), (6, 8), (7, 5), (7, 6), (7, 8), (8, 5), (8, 6), (8, 7)]\n"], "entry_point": "f_37964", "intent": "\u00bfC\u00f3mo generar permutaciones de una lista `mi_lista` permitiendo repetir elementos y sin repetirlos?", "library": []} {"task_id": 54164, "prompt": "def f_54164(dic):\n\t", "suffix": "\n\treturn list", "canonical_solution": "list = [] \n\tfor id,mensaje in dic.items():\n\t list.append([mensaje['Lon'],mensaje['Lat']])", "test_start": "\ndef check(candidate):", "test": ["\n dic = {3: {'Lat': 32.144, 'Lon':-112.56}, 7: {'Lat': 21.144, 'Lon': 98.56}}\n list = candidate(dic)\n assert len(list) == 2\n"], "entry_point": "f_54164", "intent": "\u00bfC\u00f3mo crear una lista `list` de tuplas con los valores `Lon` y `Lat` de un diccionario `dic`?", "library": []} {"task_id": 54164, "prompt": "def f_54164(dic):\n\t", "suffix": "\n\treturn list", "canonical_solution": "list = [[v['Lon'],v['Lat']] for k, v in dic.items()]", "test_start": "\ndef check(candidate):", "test": ["\n dic = {3: {'Lat': 32.144, 'Lon':-112.56}, 7: {'Lat': 21.144, 'Lon': 98.56}}\n list = candidate(dic)\n assert len(list) == 2\n"], "entry_point": "f_54164", "intent": "\u00bfC\u00f3mo crear una lista `list` de tuplas con los valores `Lon` y `Lat` de un diccionario `dic`?", "library": []} {"task_id": 36164, "prompt": "def f_36164():\n\t", "suffix": "\n\treturn indextoentry", "canonical_solution": "def indextoentry(lista,index):\n\t return [lista[index]]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate()([1,2,3], 0) == [1]\n"], "entry_point": "f_36164", "intent": "\u00bfC\u00f3mo crear una funci\u00f3n `indextoentry` que devuelva una lista al pasarle una lista `lista` y un \u00ecndice `index`?", "library": []} {"task_id": 59300, "prompt": "def f_59300():\n\t", "suffix": "\n\treturn lista", "canonical_solution": "lista = []\n\twhile True:\n\t inputs = input()\n\t if inputs:\n\t lista.append(inputs)\n\t else:\n\t break\n\tprint(lista)", "test_start": "\nimport builtins\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n builtins.input = Mock(return_value=\"hello\")\n try:\n candidate()\n except:\n return True\n"], "entry_point": "f_59300", "intent": "\u00bfC\u00f3mo leer una cadena de varias l\u00edneas ingresada por consola y almacenar cada l\u00ednea como un elemento de una lista `lista`?", "library": ["builtins"]} {"task_id": 2056, "prompt": "def f_2056(rut):\n\t", "suffix": "\n\treturn ", "canonical_solution": "directory = rut\n\tos.chdir(directory)\n\tfor filename in glob.glob('**/*.txt', recursive=True):\n\t os.unlink(filename)", "test_start": "\nimport os\nimport glob\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n os.chdir = Mock()\n os.unlink = Mock()\n try:\n candidate('/')\n except:\n assert False\n"], "entry_point": "f_2056", "intent": "\u00bfC\u00f3mo borrar todos los archivos .txt dentro de las subcarpetas ubicadas en la ruta `rut`?", "library": ["glob", "os"]} {"task_id": 59326, "prompt": "def f_59326(proxies, url):\n\t", "suffix": "\n\treturn ", "canonical_solution": "proxy = request.ProxyHandler(proxies)\n\topener = request.build_opener(proxy)\n\trequest.install_opener(opener)\n\tresponse=request.urlopen(url)", "test_start": "\nfrom urllib import request\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n proxies = {'http':\"218.28.112.114:809\"}\n url = 'http://www.httpbin.org/ip'\n request.ProxyHandler = Mock()\n request.build_opener = Mock()\n request.install_opener = Mock()\n request.urlopen = Mock(return_value = request.urlopen('https://www.google.com'))\n try:\n candidate(proxies, url)\n except:\n assert False\n"], "entry_point": "f_59326", "intent": "\u00bfC\u00f3mo usar una direcci\u00f3n proxy `proxies` con una url `url`?", "library": ["urllib"]} {"task_id": 3995, "prompt": "def f_3995(conf):\n\t", "suffix": "\n\treturn config", "canonical_solution": "\n\tconfig = configparser.ConfigParser()\n\tconfig.read(conf)\n", "test_start": "\nimport configparser\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n file_name = 'example.conf'\n with open(file_name, 'w') as f:\n f.write('[HORAS]\\n')\n f.write('hora_ini = 14:00\\n')\n f.write('hora_fin = 22:00\\n')\n try:\n candidate(file_name)\n except:\n assert False\n"], "entry_point": "f_3995", "intent": "\u00bfC\u00f3mo implementar un fichero conf?", "library": ["configparser"]} {"task_id": 19685, "prompt": "def f_19685(ingreso):\n\t", "suffix": "\n\treturn diferencia", "canonical_solution": "now = datetime.utcnow() \n\tdiferencia = now - ingreso", "test_start": "\nfrom datetime import datetime\n\ndef check(candidate):", "test": ["\n ingreso = datetime.utcnow()\n assert candidate(ingreso).seconds - (datetime.utcnow()-ingreso).seconds < 60\n"], "entry_point": "f_19685", "intent": "\u00bfC\u00f3mo calcular la diferencia entre una hora `ingreso` en UTC y este momento?", "library": ["datetime"]} {"task_id": 19685, "prompt": "def f_19685(ingreso):\n\t", "suffix": "\n\treturn diferencia", "canonical_solution": "now = datetime.utcnow()\n\tdiferencia = now.replace(tzinfo=None) - ingreso.replace(tzinfo=None)", "test_start": "\nimport datetime\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n datetime.utcnow = Mock(return_value = datetime.datetime(2016, 8, 1, 22, 0, 21, 979170))\n ingreso = datetime.datetime(2016, 8, 2, 22, 0, 21, 979170)\n d = candidate(ingreso)\n assert d.days == -1\n"], "entry_point": "f_19685", "intent": "\u00bfC\u00f3mo calcular la diferencia entre una hora `ingreso` en UTC y este momento?", "library": ["datetime"]} {"task_id": 2256, "prompt": "def f_2256(S):\n\t", "suffix": "\n\treturn mayores, menores", "canonical_solution": "media = stats.mean([len(palabra) for palabra in S.split()])\n\tmayores = [palabra for palabra in S.split() if len(palabra) >= media]\n\tmenores = [palabra for palabra in S.split() if len(palabra) < media]\n\tprint('las palabras menores a la media: ', menores)\n\tprint('las palabras mayores o iguales a la media: ', mayores)", "test_start": "\nimport statistics as stats\n\ndef check(candidate):", "test": ["\n S = \"hello world i am a penguin\"\n x, y = candidate(S)\n assert y == ['i', 'am', 'a']\n assert x == ['hello', 'world', 'penguin']\n"], "entry_point": "f_2256", "intent": "\u00bfC\u00f3mo encontrar las palabras de longitud menor `menores` o mayor `mayores` que la media aritmetica de una cadena `S`?", "library": ["statistics"]} {"task_id": 2256, "prompt": "def f_2256(S):\n\t", "suffix": "\n\treturn mayores, menores", "canonical_solution": "\n\tls, ts = zip(*sorted([(len(x), x) for x in S.split()]))\n\tavlen = sum(ls) / len(ls) \n\tbpoint = bisect.bisect_right(ls, avlen) \n\tmayores = ts[bpoint:]\n\tmenores = ts[:bpoint]\n", "test_start": "\nimport bisect\nimport statistics as stats\n\ndef check(candidate):", "test": ["\n S = \"hello world i am a penguin\"\n x, y = candidate(S)\n assert x == ('hello', 'world', 'penguin')\n assert y == ('a', 'i', 'am')\n"], "entry_point": "f_2256", "intent": "\u00bfC\u00f3mo encontrar las palabras de longitud menor `menores` o mayor `mayores` que la media aritmetica de una cadena `S`?", "library": ["bisect", "statistics"]} {"task_id": 62209, "prompt": "def f_62209(A, B, P):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tif all(A==P) or all(B==P):\n\t\treturn 0\n\telif np.arccos(np.dot((P-A)/norm(P-A), (B-A)/norm(B-A))) > np.pi/2:\n\t\treturn norm(P-A)\n\telif np.arccos(np.dot((P-B)/norm(P-B), (A-B)/norm(A-B))) > np.pi/2:\n\t\treturn norm(P-B)\n\treturn norm(np.cross(B-A, A-P))/norm(B-A)\n", "test_start": "\nimport numpy as np\nfrom numpy.linalg import norm\n\ndef check(candidate):", "test": ["\n A = np.array((5,3))\n B = np.array((2,1))\n P = np.array((1,2))\n assert candidate(A, B, P) == 1.4142135623730951\n"], "entry_point": "f_62209", "intent": "\u00bfC\u00f3mo calcular la distancia entre un punto `P` y el segmento acotado por los puntos `A` y `B`?", "library": ["numpy"]} {"task_id": 62798, "prompt": "def f_62798(life, f, c):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tfs = life[f-1]\n\tfi = life[(f+1)%len(life)]\n\ti=(c+1)%len(life[0])\n\treturn (fs[c-1], fs[c], fs[i], life[f][c-1], life[f][i], fi[c-1], fi[c], fi[i]).count('#')\n", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate((['.']), 0, 0) == 0\n", "\n assert candidate((['..', '..']), 0, 0) == 0\n", "\n assert candidate((['..', '..']), 0, 1) == 0\n", "\n assert candidate((['##', '..']), 0, 0) == 2\n", "\n assert candidate((['##', '..']), 0, 1) == 2\n", "\n assert candidate((['#.', '.#']), 0, 0) == 4\n", "\n assert candidate((['##', '##']), 0, 0) == 8\n", "\n assert candidate((['.#.', '#.#', '.#.']), 1, 1) == 4\n", "\n assert candidate((['.#.', '..#', '.#.']), 1, 1) == 3\n"], "entry_point": "f_62798", "intent": "\u00bfC\u00f3mo encontrar las celdas adyacentes a la celda en la fila `f` y la columna `c` en una matriz `life` llena de #?", "library": []} {"task_id": 34346, "prompt": "def f_34346(dbname, user, password, host):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tport = 3306\n\tengine = sqlalchemy.create_engine('mysql://'+user+':'+password+'@+'+str(host)+'/'+dbname+'?charset=utf8&use_unicode=0', pool_recycle=port)\n\tconnection = engine.connect()\n", "test_start": "\nimport sqlalchemy\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n class my_engine:\n def __init__(self):\n pass\n def connect(self):\n return 0\n engine = my_engine()\n sqlalchemy.create_engine = Mock(return_value = engine)\n try:\n candidate('gaurishankar', 'hyena', 'hyena123', '127.0.0.1')\n except:\n assert False\n"], "entry_point": "f_34346", "intent": "\u00bfComo conectarme con SQLALCHEMY a una basededatos `dbname` con usuario `user`, contrase\u00f1a `password`, host `host` y ?", "library": ["sqlalchemy"]} {"task_id": 26959, "prompt": "def f_26959():\n\t", "suffix": "\n\treturn mcd", "canonical_solution": "def mcd(a,b):\n\t return next((i for i in range(min(a,b),0,-1) if a%i==0 and b%i==0), 0)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate()(25, 30) == 5\n", "\n assert candidate()(24, 30) == 6\n", "\n assert candidate()(23, 30) == 1\n"], "entry_point": "f_26959", "intent": "\u00bfC\u00f3mo calcular el m\u00e1ximo com\u00fan divisor entre dos n\u00fameros `a` y `b`?", "library": []} {"task_id": 44385, "prompt": "def f_44385(command):\n\t", "suffix": "\n\treturn output", "canonical_solution": "process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True)\n\t\n\toutput = process.communicate()\n\t\n\tprint(output[0])", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n class Process:\n def __init__(self):\n pass\n def communicate(self):\n return [1, 2, 3]\n proc = Process()\n subprocess.Popen = Mock(return_value = proc)\n assert candidate('python3')[0] == 1\n"], "entry_point": "f_44385", "intent": "\u00bfC\u00f3mo capturar la salida del terminal despu\u00e9s de ejecutar un comando `command`?", "library": ["subprocess"]} {"task_id": 28562, "prompt": "def f_28562(S):\n\treturn ", "suffix": "", "canonical_solution": "int(S)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('123') == 123\n", "\n assert candidate('10000') == 10000\n", "\n assert candidate('0') == 0\n"], "entry_point": "f_28562", "intent": "\u00bfC\u00f3mo convertir un string `S` a un entero?", "library": []} {"task_id": 17560, "prompt": "def f_17560(old, new):\n\treturn ", "suffix": "", "canonical_solution": "os.rename(old, new)", "test_start": "\nimport os\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n os.rename = Mock()\n try:\n candidate('a.py', 'b.py')\n except:\n assert False\n"], "entry_point": "f_17560", "intent": "\u00bfC\u00f3mo renombrar un archivo con nombre `old` a `new`?", "library": ["os"]} {"task_id": 41536, "prompt": "def f_41536(ruta):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tpath = ruta\n\textension = '*.ext'\n\n\tdef comparar_linea(file1, file2):\n\t\tdata1 = [line.strip() for line in file1.readlines()]\n\t\tdata2 = [line.strip() for line in file2.readlines()]\n\t\tsame = set(data1).intersection(data2)\n\t\treturn same\n\n\tdef buscarCoincidencias(path, extension):\n\t\twith open('some_output_file.txt', 'w') as file_out:\n\t\t\tos.chdir(path)\n\t\t\tfiles = glob.glob(extension)\n\t\t\tprint(files)\n\t\t\tfor i in range(len(files)):\n\t\t\t\tfor j in range(i+1, len(files)):\n\t\t\t\t\twith open(files[i]) as file1:\n\t\t\t\t\t\twith open(files[j], 'r') as file2:\n\t\t\t\t\t\t\tsame = comparar_linea(file1, file2)\n\t\t\t\t\t\t\tfile_out.write(files[i] + \"-\"+ files[j] + \": \"+str(same)+\"\\n\")\n\n\tbuscarCoincidencias(path, extension)\n", "test_start": "\nimport os\nimport glob\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n file_name = 'some_output_file.txt'\n arr = ['a.ext', 'b.ext', 'c.ext']\n for file in arr:\n with open (file, 'w') as f:\n f.write('1')\n\n\n os.chdir = Mock()\n candidate('/')\n f = open('some_output_file.txt')\n lines = f.readlines()\n assert len(lines) == 3\n f.close()\n"], "entry_point": "f_41536", "intent": "\u00bfC\u00f3mo buscar todos los archivos con extensi\u00f3n `.ext` en la ruta `ruta` y buscar las coincidencias entre ellos?", "library": ["glob", "os"]} {"task_id": 40594, "prompt": "def f_40594(M, x):\n\treturn ", "suffix": "", "canonical_solution": "M.transpose() + x.transpose()", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n M = np.array([[1,2],[3,4],[5,6]])\n x = np.array([10, 100, 1000])\n assert np.all(candidate(M, x) == np.array([[ 11, 103, 1005],[12, 104, 1006]]))\n"], "entry_point": "f_40594", "intent": "\u00bfC\u00f3mo sumar los valores del vector `x` a todas las columnas de la matriz `M`?", "library": ["numpy"]} {"task_id": 61810, "prompt": "def f_61810(A, B):\n\treturn ", "suffix": "", "canonical_solution": "[[sum(x * B[i][col] for i,x in enumerate(fila)) for col in range(len(B[0]))] for fila in A]", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n assert (candidate([[1,2],[3,4]], [[5,6],[7,8]]) == [[19, 22], [43, 50]]) or (candidate(np.array([[1,2],[3,4]]), np.array([[5,6],[7,8]]))) == np.array([[19, 22], [43, 50]])\n"], "entry_point": "f_61810", "intent": "\u00bfC\u00f3mo multiplicar la matriz `A` y la matriz `B`?", "library": ["numpy"]} {"task_id": 63234, "prompt": "def f_63234(x, list):\n\treturn ", "suffix": "", "canonical_solution": "list.index(x)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(3, [1,2,3,4]) == 2\n", "\n assert candidate(0, [0,0,0,0]) == 0\n"], "entry_point": "f_63234", "intent": "\u00bfC\u00f3mo obtener la posici\u00f3n de un dato `x` en una lista `list`?", "library": []} {"task_id": 57263, "prompt": "def f_57263(INT, STR):\n\treturn ", "suffix": "", "canonical_solution": "repr(INT) + STR", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(2, 'a') == '2a'\n", "\n assert candidate(-1, ' ') == '-1 '\n"], "entry_point": "f_57263", "intent": "\u00bfC\u00f3mo concatenar un `INT` y un `STR`?", "library": []} {"task_id": 87813, "prompt": "def f_87813(L):\n\treturn ", "suffix": "", "canonical_solution": "list(set(L))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,1,1,1]) == [1]\n", "\n assert candidate([1,2,3,4]) == [1,2,3,4]\n", "\n assert candidate([]) == []\n"], "entry_point": "f_87813", "intent": "\u00bfC\u00f3mo eliminar duplicados en una lista `L`?", "library": []} {"task_id": 15622, "prompt": "def f_15622(x):\n\treturn ", "suffix": "", "canonical_solution": "type(x)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3]) == list\n", "\n assert candidate({'a': None}) == dict\n", "\n assert candidate(123) == int\n", "\n assert candidate(12.34) == float\n"], "entry_point": "f_15622", "intent": "\u00bfC\u00f3mo obtener el tipo de una variable `x`?", "library": []} {"task_id": 201210, "prompt": "def f_201210(lista):\n\treturn ", "suffix": "", "canonical_solution": "sum(lista)", "test_start": "\ndef check(candidate):", "test": ["\n assert (candidate([1,2,3]) - 6) < 1e-6\n", "\n assert (candidate([0.0, 3.5, 2.7, 1.8, 2.0]) - 10.0) < 1e-6\n"], "entry_point": "f_201210", "intent": "\u00bfC\u00f3mo sumar todos los elementos de una `lista`?", "library": []} {"task_id": 124063, "prompt": "def f_124063(n):\n\t", "suffix": "\n\treturn L", "canonical_solution": "L = [random.randint(0, 1000) for i in range(n)]", "test_start": "\nimport random\n\ndef check(candidate):", "test": ["\n assert len(candidate(100)) == 100\n", "\n assert len(candidate(0)) == 0\n"], "entry_point": "f_124063", "intent": "\u00bfC\u00f3mo crear una lista `L` con `n` n\u00fameros aleatorios?", "library": ["random"]} {"task_id": 8510, "prompt": "def f_8510(num):\n\treturn ", "suffix": "", "canonical_solution": "math.ceil(num)", "test_start": "\nimport math\n\ndef check(candidate):", "test": ["\n assert candidate(3.8) == 4\n", "\n assert candidate(4.0) == 4\n", "\n assert candidate(76.4) == 77\n"], "entry_point": "f_8510", "intent": "\u00bfC\u00f3mo redondear decimales hacia arriba de un n\u00famero `num`?", "library": ["math"]} {"task_id": 114782, "prompt": "def f_114782(s):\n\treturn ", "suffix": "", "canonical_solution": "sum([int(c in 'aeiouAEIOU') for c in s])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('mvfbgndvsh') == 0\n", "\n assert candidate('vowel') == 2\n", "\n assert candidate('AAAAABBC') == 5\n"], "entry_point": "f_114782", "intent": "\u00bfC\u00f3mo contar las vocales en una cadena `s`?", "library": []} {"task_id": 159996, "prompt": "def f_159996(n, m):\n\t", "suffix": "\n\treturn matriz", "canonical_solution": "matriz = []\n\t\n\tfor i in range(n):\n\t matriz.append([])\n\t for j in range(m):\n\t matriz[i].append(random.randint(0, 100))", "test_start": "\nimport random \n\ndef check(candidate):", "test": ["\n matriz = candidate(2,3)\n assert len(matriz) == 2 and all(len(row)==3 for row in matriz)\n"], "entry_point": "f_159996", "intent": "\u00bfC\u00f3mo crear una matriz `matriz` con `n` filas y `m` columnas?", "library": ["random"]} {"task_id": 159996, "prompt": "def f_159996(n, m):\n\t", "suffix": "\n\treturn matriz", "canonical_solution": "matriz = np.random.randint(0, 100, size=(n, m))", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n matriz = candidate(2,3)\n assert len(matriz) == 2 and all(len(row)==3 for row in matriz)\n"], "entry_point": "f_159996", "intent": "\u00bfC\u00f3mo crear una matriz `matriz` con `n` filas y `m` columnas?", "library": ["numpy"]} {"task_id": 14454, "prompt": "def f_14454(l):\n\t", "suffix": "\n\treturn sel", "canonical_solution": "shuffle(l)\n\tsel = l[0]", "test_start": "\nimport random\nfrom random import shuffle\n\ndef check(candidate):", "test": ["\n results = [candidate([1,2,3,4,5]) for i in range(10)]\n assert all([(x in [1,2,3,4,5]) for x in results])\n assert len(set(results)) > 1\n"], "entry_point": "f_14454", "intent": "\u00bfC\u00f3mo seleccionar un elemento aleatorio de una lista `l`?", "library": ["random"]} {"task_id": 14454, "prompt": "def f_14454(l):\n\t", "suffix": "\n\treturn sel", "canonical_solution": "sel = random.sample(l, 1)", "test_start": "\nimport random\n\ndef check(candidate):", "test": ["\n results = [candidate([1,2,3,4,5])[0] for i in range(10)]\n assert all([(x in [1,2,3,4,5]) for x in results])\n assert len(set(results)) > 0\n"], "entry_point": "f_14454", "intent": "\u00bfC\u00f3mo seleccionar un elemento aleatorio de una lista `l`?", "library": ["random"]} {"task_id": 46558, "prompt": "def f_46558(l, n):\n\treturn ", "suffix": "", "canonical_solution": "max(l, key=itemgetter(n))[n]", "test_start": "\nfrom operator import itemgetter \n\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3],[4,5,6], [-1,-2,0]], 0) == 4\n"], "entry_point": "f_46558", "intent": "\u00bfC\u00f3mo encontrar el mayor elemento en la posici\u00f3n `n` una lista de listas `l`?", "library": ["operator"]} {"task_id": 213125, "prompt": "def f_213125(list):\n\t", "suffix": "\n\treturn list", "canonical_solution": "for i in range(len(list)):\n\t list[i] = int(list[i])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['0','1','2','3','4']) == [0,1,2,3,4]\n", "\n assert candidate(['100','444','45']) == [100, 444, 45]\n"], "entry_point": "f_213125", "intent": "\"C\u00f3mo convertir una lista `list` de tipo `str` a una de tipo `int`\"", "library": []} {"task_id": 151572, "prompt": "def f_151572(lista):\n\treturn ", "suffix": "", "canonical_solution": "Counter(lista).most_common()[0][0]", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n assert candidate([1,1,2,3,4]) == 1\n", "\n assert candidate([8,2,5,7,3,7]) == 7\n"], "entry_point": "f_151572", "intent": "\u00bfC\u00f3mo hallar el numero mas repetido de una `lista`?", "library": ["collections"]} {"task_id": 115010, "prompt": "def f_115010(c, m):\n\treturn ", "suffix": "", "canonical_solution": "np.array(m)[:, c]", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert all(candidate(1, np.array([[1,2],[3,4],[5,6]])) == np.array([2, 4, 6]))\n"], "entry_point": "f_115010", "intent": "\u00bfC\u00f3mo obtener toda una columna `c` de una matriz `m`?", "library": ["numpy"]} {"task_id": 206450, "prompt": "def f_206450(L, n):\n\t", "suffix": "\n\treturn L", "canonical_solution": "L.remove(n)", "test_start": "\ndef check(candidate):", "test": ["\n L = [i for i in range(8)]\n assert candidate(L, 3) == [0,1,2,4,5,6,7]\n", "\n L = [0,1,2,4,5,6,7]\n assert candidate(L, 5) == [0,1,2,4,6,7]\n", "\n L = [0,1,2,4,6,7]\n assert candidate(L, 0) == [1,2,4,6,7]\n"], "entry_point": "f_206450", "intent": "\u00bfC\u00f3mo crear una funci\u00f3n para eliminar un elemento `n` de una lista `L`?", "library": []} {"task_id": 148791, "prompt": "def f_148791(L):\n\treturn ", "suffix": "", "canonical_solution": "sum(L)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4,5]) == 15\n", "\n assert candidate([0, 1, -1, 2, 2]) == 4\n", "\n assert candidate([3.4, 5.8, 6.6, 19.2]) == 35\n"], "entry_point": "f_148791", "intent": "\u00bfC\u00f3mo realizar una sumatoria de una lista `L` sin utilizar ciclos?", "library": []} {"task_id": 8239, "prompt": "def f_8239(L, M, N):\n\treturn ", "suffix": "", "canonical_solution": "np.array(L).reshape(M,N)", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4],2,2).tolist() == [[1,2],[3,4]]\n", "\n assert np.all(candidate([i for i in range(100)], 10, 10) == np.array([[i*10+j for j in range(10)] for i in range(10)]))\n"], "entry_point": "f_8239", "intent": "\u00bfC\u00f3mo generar una matr\u00edz de `M`x`N` con una lista `L`?", "library": ["numpy"]} {"task_id": 83439, "prompt": "def f_83439(L):\n\treturn ", "suffix": "", "canonical_solution": "[i for i,x in enumerate(L) if L.count(x) > 1]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,1,2,2,3,3]) == [0,1,2,3,4,5]\n", "\n assert candidate([1,2,3,4,5,6]) == []\n", "\n assert candidate([100, 101, 102, 100]) == [0, 3]\n"], "entry_point": "f_83439", "intent": "\u00bfC\u00f3mo mostrar la posici\u00f3n de los elementos repetidos en una lista `L`?", "library": []} {"task_id": 188925, "prompt": "def f_188925(S):\n\treturn ", "suffix": "", "canonical_solution": "Counter(S)", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n assert candidate('apple') == Counter({'a': 1, 'e': 1, 'l': 1, 'p': 2})\n", "\n assert candidate('') == Counter({})\n"], "entry_point": "f_188925", "intent": "\u00bfC\u00f3mo contar cu\u00e1ntas veces se repite un car\u00e1cter en una cadena `S`?", "library": ["collections"]} {"task_id": 134908, "prompt": "def f_134908(L, n):\n\treturn ", "suffix": "", "canonical_solution": "[L[i:i + n] for i in range(0, len(L), n)]", "test_start": "\nimport os\n\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4,5,6],3) == [[1,2,3],[4,5,6]]\n", "\n assert candidate([1,2,3,4],1) == [[1],[2],[3],[4]]\n"], "entry_point": "f_134908", "intent": "\u00bfC\u00f3mo dividir una lista `L` en una lista de listas cada `n` datos?", "library": ["os"]} {"task_id": 52839, "prompt": "def f_52839(S):\n\t", "suffix": "\n\treturn M, m, n", "canonical_solution": "M = len([c for c in S if c.isupper()])\n\tm = len([c for c in S if c.islower()])\n\tn = len([c for c in S if c.isdigit()])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('ceg242AABd ') == (3,4,3)\n", "\n assert candidate('12233457') == (0,0,8)\n"], "entry_point": "f_52839", "intent": "\u00bfC\u00f3mo saber cu\u00e1ntas may\u00fasculas `M`, cu\u00e1ntas min\u00fasculas `m` y cu\u00e1ntos n\u00fameros `n` tiene un string `S`?", "library": []} {"task_id": 50423, "prompt": "def f_50423(n):\n\treturn ", "suffix": "", "canonical_solution": "int(n, 2)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('1100') == 12\n", "\n assert candidate('001010111') == 87\n", "\n assert candidate('0') == 0\n"], "entry_point": "f_50423", "intent": "\u00bfC\u00f3mo convertir un n\u00famero binario `n` a entero?", "library": []} {"task_id": 39861, "prompt": "def f_39861(S):\n\t", "suffix": "\n\treturn L1, L2, L3, L4", "canonical_solution": "L1, L2, L3, L4 = random.sample(S, 4)", "test_start": "\nimport random \n\ndef check(candidate):", "test": ["\n L1, L2, L3, L4 = candidate([1,2,3,4,5,6,7,8])\n s = set([L1,L2,L3,L4])\n assert len(s) == 4\n assert s < set([i+1 for i in range(8)])\n"], "entry_point": "f_39861", "intent": "\u00bfC\u00f3mo escoger cuatro valores aleatorios `L1`, `L2`, `L3`, `L4` de una cadena `S` sin repetir?", "library": ["random"]} {"task_id": 22582, "prompt": "def f_22582(lista):\n\treturn ", "suffix": "", "canonical_solution": "list(zip(*[iter(lista)]*2))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4]) == [(1,2),(3,4)]\n", "\n assert candidate([1,'a',33.5,None]) == [(1,'a'),(33.5,None)]\n"], "entry_point": "f_22582", "intent": "\u00bfC\u00f3mo crear una lista de tuplas de 2 valores a partir de una lista `lista`?", "library": []} {"task_id": 1651, "prompt": "def f_1651(num):\n\treturn ", "suffix": "", "canonical_solution": "sum([int(c) for c in str(num)])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(10) == 1\n", "\n assert candidate(100) == 1\n", "\n assert candidate(1234) == 10\n"], "entry_point": "f_1651", "intent": "\u00bfC\u00f3mo obtener la ra\u00edz digital de un n\u00famero `num`?", "library": []} {"task_id": 1139, "prompt": "def f_1139(date):\n\treturn ", "suffix": "", "canonical_solution": "date.strftime('%y%j')", "test_start": "\nimport datetime\n\ndef check(candidate):", "test": ["\n date = datetime.datetime.now()\n assert candidate(date) == date.strftime('%y%j')\n"], "entry_point": "f_1139", "intent": "\u00bfC\u00f3mo obtener los dos \u00faltimos d\u00edgitos del a\u00f1o seguidos del d\u00eda del a\u00f1o desde un datetime `date`?", "library": ["datetime"]} {"task_id": 15727, "prompt": "def f_15727(S):\n\treturn ", "suffix": "", "canonical_solution": "S.upper()", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('mystring') == 'MYSTRING'\n", "\n assert candidate('myString') == 'MYSTRING'\n", "\n assert candidate('MySTRinG') == 'MYSTRING'\n", "\n assert candidate('MYSTRING') == 'MYSTRING'\n"], "entry_point": "f_15727", "intent": "\u00bfC\u00f3mo convertir de min\u00fasculas a may\u00fasculas un string `S`?", "library": []} {"task_id": 47500, "prompt": "def f_47500(num, num1):\n\treturn ", "suffix": "", "canonical_solution": "num / num1", "test_start": "\ndef check(candidate):", "test": ["\n assert (candidate(1, 1.0) - 1.0) < 1e-6\n", "\n assert (candidate(10, 3.3) - 3.0303) < 0.01\n"], "entry_point": "f_47500", "intent": "\u00bfC\u00f3mo dividir un n\u00famero entero `num` por un n\u00famero `num1` decimal?", "library": []} {"task_id": 49118, "prompt": "def f_49118(S):\n\t", "suffix": "\n\treturn num", "canonical_solution": "num = sum([int('ch' in w) for w in S.split()])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('chain of words color cook zero chaos') == 2\n"], "entry_point": "f_49118", "intent": "\u00bfC\u00f3mo calcular el n\u00famero de palabras `num` que contengan la letra `ch` en un texto `S`?", "library": []} {"task_id": 96261, "prompt": "def f_96261(L1, L2):\n\treturn ", "suffix": "", "canonical_solution": "list(map(operator.mul, L1, L2))", "test_start": "\nimport operator\n\ndef check(candidate):", "test": ["\n assert candidate([3,4,2,6],[98,80,86,78]) == [294, 320, 172, 468]\n", "\n assert candidate([i for i in range(10)], [0 for i in range(10)]) == [0,0,0,0,0,0,0,0,0,0]\n"], "entry_point": "f_96261", "intent": "\u00bfC\u00f3mo puedo multiplicar dos listas de `INT` `L1` y `L2` ?", "library": ["operator"]} {"task_id": 96261, "prompt": "def f_96261(L1, L2):\n\treturn ", "suffix": "", "canonical_solution": "np.multiply(L1,L2)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n assert all(candidate(np.array([3,4,2,6]),np.array([98,80,86,78])) == np.array([294, 320, 172, 468]))\n", "\n assert all(candidate(np.array([i for i in range(10)]), np.array([0 for i in range(10)])) == np.array([0,0,0,0,0,0,0,0,0,0]))\n"], "entry_point": "f_96261", "intent": "\u00bfC\u00f3mo puedo multiplicar dos listas de `INT` `L1` y `L2` ?", "library": ["numpy"]} {"task_id": 24577, "prompt": "def f_24577(L, x):\n\treturn ", "suffix": "", "canonical_solution": "np.where(L == x)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n assert candidate(np.array([1,2,3,4,5]), 4)[0].tolist() == [3]\n", "\n assert candidate(np.array([1,2,3,4,5]), 100)[0].tolist() == []\n"], "entry_point": "f_24577", "intent": "\u00bfC\u00f3mo obtener las posiciones del array `L` donde encuentre un valor `x`?", "library": ["numpy"]} {"task_id": 148266, "prompt": "def f_148266(df, type):\n\t", "suffix": "\n\treturn df1", "canonical_solution": "df1 = df.select_dtypes(include=[type])", "test_start": "\nimport numpy as np\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n assert candidate(pd.DataFrame({'a':[1,2,3], 'b':[1.,2.,3.]}), np.float).equals(pd.DataFrame({'b':[1.,2.,3.]}))\n"], "entry_point": "f_148266", "intent": "\u00bfC\u00f3mo crear un dataframe `df1` a partir de otro dataframe `df` filtrando columnas que contengan \u00fanicamente datos de tipo \u00b4type\u00b4?", "library": ["numpy", "pandas"]} {"task_id": 104440, "prompt": "def f_104440(df):\n\t", "suffix": "\n\treturn new_df", "canonical_solution": "new_df = df.astype('str')\n\tnew_df[new_df == \"1\"] = 'Presente'\n\tnew_df[new_df == \"0\"] = 'Falta'", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df1 = pd.DataFrame({'a':[1,0,3], 'b': [0,1,4]})\n df2 = pd.DataFrame({'a':['sobra','falta',3], 'b': ['falta','sobra',4]})\n assert all(candidate(df1) == df2)\n"], "entry_point": "f_104440", "intent": "\u00bfC\u00f3mo puedo sustituir valores `falta` si el valor es 0 y `sobra` si el valor es 1 '' en un dataframe `df`?", "library": ["pandas"]} {"task_id": 33325, "prompt": "def f_33325(num):\n\treturn ", "suffix": "", "canonical_solution": "num == 0 or num % ((10**int(log10(abs(num))+1) - 1) // 9) == 0", "test_start": "\nimport math\nfrom math import log10\n\ndef check(candidate):", "test": ["\n assert candidate(1111) == True\n", "\n assert candidate(1211) == False\n", "\n assert candidate(0) == True\n"], "entry_point": "f_33325", "intent": "\u00bfC\u00f3mo determinar si todos los d\u00edgitos de un n\u00famero entero `num` son iguales?", "library": ["math"]} {"task_id": 314, "prompt": "def f_314(a, b):\n\treturn ", "suffix": "", "canonical_solution": "tuple(sum(x) for x in zip(a, b))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate((1,2,3),(4,5,6)) == (5,7,9)\n", "\n assert candidate((1,2,3),(4,5,6)) != [5,7,9]\n"], "entry_point": "f_314", "intent": "\u00bfC\u00f3mo sumar dos vectores `a` y `b` representados por tuplas?", "library": []} {"task_id": 87732, "prompt": "def f_87732(dic):\n\t", "suffix": "\n\treturn dic2", "canonical_solution": "dic2 = {key: [sum(value)] for key, value in dic.items()}", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'11': [1,2,3], '22': [34.0, 1]}) == {'11': [6], '22': [35.0]}\n", "\n assert candidate({0: [10,20,-10,-20]}) == {0: [0]}\n", "\n assert candidate({'random_key': [10,20,-10,-20], 'random_key1': [-1,-2]}) == {'random_key': [0], 'random_key1': [-3]}\n", "\n assert candidate({1: [0]}) == {1: [0]}\n", "\n assert candidate({1: [], 2:[2]}) == {1: [0], 2: [2]}\n"], "entry_point": "f_87732", "intent": "\u00bfC\u00f3mo crear un diccionario `dic2` con la suma de los valores de cada una de las llaves en un diccionario `dic`?", "library": []} {"task_id": 87732, "prompt": "def f_87732(dic):\n\t", "suffix": "\n\treturn dic2", "canonical_solution": "\n\tdef suma_valores_dic(dic):\n\t\tdic2 = {}\n\t\tfor key, value in dic.items():\n\t\t\tsuma = 0\n\t\t\tfor v in value:\n\t\t\t\tsuma += v\n\t\t\tdic2[key] = suma\n\t\treturn dic2\n\tdic2 = suma_valores_dic(dic)\n", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'11': [1,2,3], '22': [34.0, 1]}) == {'11': 6, '22': 35.0}\n", "\n assert candidate({0: [10,20,-10,-20]}) == {0: 0}\n", "\n assert candidate({'random_key': [10,20,-10,-20], 'random_key1': [-1,-2]}) == {'random_key': 0, 'random_key1': -3}\n", "\n assert candidate({1: [0]}) == {1: 0}\n", "\n assert candidate({1: [], 2:[2]}) == {1: 0, 2: 2}\n"], "entry_point": "f_87732", "intent": "\u00bfC\u00f3mo crear un diccionario `dic2` con la suma de los valores de cada una de las llaves en un diccionario `dic`?", "library": []} {"task_id": 107612, "prompt": "def f_107612(file1, file2, file3):\n\t", "suffix": "\n\treturn process1, process2, process3", "canonical_solution": "process1 = subprocess.Popen(['python', file1])\n\tprocess2 = subprocess.Popen(['python', file2])\n\tprocess3 = subprocess.Popen(['python', file3])", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.Popen = Mock(return_value = 0)\n assert candidate(\"archive1.py\", \"archive2.py\", \"archive3.py\") == (0, 0, 0)\n"], "entry_point": "f_107612", "intent": "\u00bfC\u00f3mo ejecutar los archivos `file1`, `file2` y `file3` en secuencia?", "library": ["subprocess"]} {"task_id": 129553, "prompt": "def f_129553(a, b):\n\t", "suffix": "\n\treturn listas(a, b)", "canonical_solution": "\n\tdef listas(a, b):\n\t\tlista_final = []\n\t\tfor i in a:\n\t\t\tif (i not in lista_final) and (i in b):\n\t\t\t\tlista_final.append(i)\n\t\treturn lista_final\n", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,2,4,5], [7,2,5,8,10]) == [2, 5]\n"], "entry_point": "f_129553", "intent": "\u00bfC\u00f3mo obtener los elementos comunes de dos listas `a` y `b`?", "library": []} {"task_id": 129553, "prompt": "def f_129553(a, b):\n\t", "suffix": "\n\treturn intersection(a, b)", "canonical_solution": "\n\tdef intersection(a,b):\n\t\tc = []\n\t\tfor i in a:\n\t\t\tfor j in b:\n\t\t\t\tif i == j:\n\t\t\t\t\tc.append(i)\n\t\tc = list(tuple(c))\n\t\treturn c \n", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1, 2, 3, 4, 5], [1, 3, 5]) == [1, 3, 5]\n"], "entry_point": "f_129553", "intent": "\u00bfC\u00f3mo obtener los elementos comunes de dos listas `a` y `b`?", "library": []} {"task_id": 98725, "prompt": "def f_98725(lst):\n\treturn ", "suffix": "", "canonical_solution": "sorted(enumerate(lst), key=itemgetter(1), reverse=True)", "test_start": "\nfrom operator import itemgetter\n\ndef check(candidate):", "test": ["\n assert candidate([2,1,9,3,6,4,5,10,8,7]) == [(7, 10),(2, 9),(8, 8),(9, 7),(4, 6),(6, 5),(5, 4),(3, 3),(0, 2),(1, 1)]\n"], "entry_point": "f_98725", "intent": "\u00bfC\u00f3mo obtener la posici\u00f3n y el valor del segundo mayor elemento de una lista `list`?", "library": ["operator"]} {"task_id": 1732, "prompt": "def f_1732(S):\n\treturn ", "suffix": "", "canonical_solution": "sorted(S.split(), key=lambda palabra: len(palabra), reverse=True)", "test_start": "\nfrom operator import itemgetter\n\ndef check(candidate):", "test": ["\n assert candidate('hola me llamo Cesar y soy de Peru') == ['llamo', 'Cesar', 'hola', 'Peru', 'soy', 'me', 'de', 'y']\n"], "entry_point": "f_1732", "intent": "\u00bfC\u00f3mo ordenar una cadena `S` desde su palabra m\u00e1s larga a la m\u00e1s corta?", "library": ["operator"]} {"task_id": 1732, "prompt": "def f_1732(S):\n\treturn ", "suffix": "", "canonical_solution": "[i for i in reversed(sorted(S.split(), key=lambda item: len(item)))]", "test_start": "\ndef check(candidate):", "test": ["\n S = \"In addition to facilitating the new recognition process\"\n actual_result = candidate(S)\n expected_result = ['facilitating', 'recognition', 'addition', 'process', 'new', 'the', 'to', 'In']\n assert actual_result == expected_result\n"], "entry_point": "f_1732", "intent": "\u00bfC\u00f3mo ordenar una cadena `S` desde su palabra m\u00e1s larga a la m\u00e1s corta?", "library": []} {"task_id": 9367, "prompt": "def f_9367(list):\n\treturn ", "suffix": "", "canonical_solution": "[item2 for i, item in enumerate(list) for item2 in list[i:]]", "test_start": "\ndef check(candidate):", "test": ["\n array = [1, 3, 4, 6]\n assert candidate(array) == [1, 3, 4, 6, 3, 4, 6, 4, 6, 6]\n"], "entry_point": "f_9367", "intent": "\u00bfC\u00f3mo realizar una iteraci\u00f3n anidada del valor de una lista `list` y luego de los valores siguientes hasta el final?", "library": []} {"task_id": 9367, "prompt": "def f_9367(list):\n\treturn ", "suffix": "", "canonical_solution": "[list[j] for i in range(len(list)) for j in range((i+1), len(list))]", "test_start": "\ndef check(candidate):", "test": ["\n array = [4, 1, 3, 0, 9]\n assert candidate(array) == [1, 3, 0, 9, 3, 0, 9, 0, 9, 9]\n"], "entry_point": "f_9367", "intent": "\u00bfC\u00f3mo realizar una iteraci\u00f3n anidada del valor de una lista `list` y luego de los valores siguientes hasta el final?", "library": []} {"task_id": 138290, "prompt": "def f_138290(S):\n\treturn ", "suffix": "", "canonical_solution": "S[::-1]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"palindrome\") == \"emordnilap\"\n", "\n assert candidate(\"\") == \"\"\n"], "entry_point": "f_138290", "intent": "\u00bfC\u00f3mo recorrer una cadena `S` de derecha a izquierda?", "library": []} {"task_id": 364966, "prompt": "def f_364966(a):\n\treturn ", "suffix": "", "canonical_solution": "int(a)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"1\") == 1\n", "\n assert candidate(\"12\") == 12\n", "\n assert candidate(\"123\") == 123\n", "\n assert candidate(\"0000\") == 0\n"], "entry_point": "f_364966", "intent": "\u00bfC\u00f3mo convertir un dato `a` de `string` a `int`?", "library": []} {"task_id": 51410, "prompt": "def f_51410(val1, val2):\n\treturn ", "suffix": "", "canonical_solution": "val1, val2", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"1\", 2) == (\"1\", 2)\n"], "entry_point": "f_51410", "intent": "\u00bfC\u00f3mo retornar dos valores `val1` y `val2` en una funci\u00f3n?", "library": []} {"task_id": 30666, "prompt": "def f_30666(file):\n\treturn ", "suffix": "", "canonical_solution": "os.stat(file).st_size == 0", "test_start": "\nimport os\n\ndef check(candidate):", "test": ["\n f = open('test.txt', 'w')\n f.close()\n assert candidate('test.txt') == True \n", "\n with open('test.txt', 'w') as fw: fw.write(\"hello world!\")\n assert candidate('test.txt') == False\n"], "entry_point": "f_30666", "intent": "\u00bfComo verifico si un archivo `file` tiene contenido o est\u00e1 vac\u00edo?", "library": ["os"]} {"task_id": 86430, "prompt": "def f_86430(list, file):\n\t", "suffix": "\n\treturn ", "canonical_solution": "mi_path = file\n\tf = open(mi_path, 'a+')\n\t\n\tfor i in list:\n\t f.write(i)\n\t\n\tf.close()", "test_start": "\ndef check(candidate):", "test": ["\n path = 'a.txt'\n list = [\"abc\", \"def\"]\n candidate(list, path)\n f = open(path, 'r')\n lines = f.readlines()\n line = lines[0]\n assert line == \"abcdef\" \n f.close()\n"], "entry_point": "f_86430", "intent": "\u00bfC\u00f3mo iterar una lista `list` y guardar sus valores en un archivo `file`?", "library": []} {"task_id": 86430, "prompt": "def f_86430(list, file):\n\t", "suffix": "\n\treturn ", "canonical_solution": "f = open(file, \"a\")\n\t\n\tfor i in list:\n\t f.write(i)\n\t\n\tf.close()", "test_start": "\ndef check(candidate):", "test": ["\n path = 'a.txt'\n list = [\"abc\", \"def\"]\n candidate(list, path)\n f = open(path, 'r')\n lines = f.readlines()\n line = lines[0]\n assert line == \"abcdef\" \n f.close()\n"], "entry_point": "f_86430", "intent": "\u00bfC\u00f3mo iterar una lista `list` y guardar sus valores en un archivo `file`?", "library": []} {"task_id": 183061, "prompt": "def f_183061(df, col):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df['col_1'] = df[col].str.replace(',', '.').astype(float)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([\"4,99\", \"5,99\"], columns = ['vals'])\n candidate(df, 'vals')\n \n for i in range (0, len(df['vals'])):\n assert float(str(df['vals'][i]).replace(',', '.')) - df['col_1'][i] < 1e-6\n"], "entry_point": "f_183061", "intent": "\u00bfC\u00f3mo reemplazar el separador decimal de comas por puntos en la columna `col` de un DataFrame `df`?", "library": ["pandas"]} {"task_id": 183061, "prompt": "def f_183061(df, col):\n\treturn ", "suffix": "", "canonical_solution": "[float(x.replace(',','.')) for x in df[col]]", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([\"4,99\", \"5,99\"], columns = ['vals'])\n comas_por_puntos = candidate(df, 'vals')\n for i in range (0, len(df['vals'])):\n assert float(str(df['vals'][i]).replace(',', '.')) - comas_por_puntos[i] < 1e-6\n"], "entry_point": "f_183061", "intent": "\u00bfC\u00f3mo reemplazar el separador decimal de comas por puntos en la columna `col` de un DataFrame `df`?", "library": ["pandas"]} {"task_id": 61046, "prompt": "def f_61046(M):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\twith open('file.csv', 'w', newline='', encoding='utf-8') as csvfile:\n\t\twriter = csv.writer(csvfile)\n\t\twriter.writerows(M)\n", "test_start": "\nimport csv \n\ndef check(candidate):", "test": ["\n f = open ('file.csv', 'w')\n f.close()\n\n candidate([[1, 2, 3], [4, 5, 6]])\n with open ('file.csv', 'r') as f:\n lines = f.readlines()\n assert lines[0].strip() == '1,2,3'\n assert lines[1].strip() == '4,5,6'\n"], "entry_point": "f_61046", "intent": "\u00bfC\u00f3mo guardar una matriz `M` en un archivo `file.csv`?", "library": ["csv"]} {"task_id": 109768, "prompt": "def f_109768(oracion):\n\t", "suffix": "\n\treturn mayor, menor", "canonical_solution": "mayor=''\n\tmenor=''\n\tpalabra=''\n\t\n\tfor c in oracion:\n\t if c == ' ':\n\t if palabra != '':\n\t mayor = palabra if len(mayor)len(palabra) or menor == '' else menor\n\t\n\t palabra = ''\n\t\n\t palabra = palabra + c\n\t\n\tprint(mayor)\n\tprint(menor)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"Maria had a little lamb named peepeepoopoo\") == (' little', ' a')\n", "\n assert candidate(\"12345 123 1\") == ('12345', ' 123')\n"], "entry_point": "f_109768", "intent": "\u00bfC\u00f3mo determinar la palabra m\u00e1s larga `mayor` y la m\u00e1s corta `menor` de un String `S`?", "library": []} {"task_id": 191740, "prompt": "def f_191740(df, col):\n\treturn ", "suffix": "", "canonical_solution": "df[col].std()", "test_start": "\nimport pandas as pd\nimport numpy as np\n\ndef check(candidate):", "test": ["\n data = {\"A\": (8.65, 24.53, 13.25, np.NaN, 4.03, 4.55, 14.31, 4.54, 8.57, 4.72),\n \"B\": pd.timedelta_range('1s', periods=10),\n \"C\": (3, 12, 13, 4, 5, 7, 9, np.NaN, 17, 19)\n }\n df = pd.DataFrame(data)\n assert candidate(df, 'A') == 6.766256350449634\n"], "entry_point": "f_191740", "intent": "\u00bfC\u00f3mo calcular la desviaci\u00f3n est\u00e1ndar de la columna `col` en un DataFrame `df`?", "library": ["numpy", "pandas"]}