forked from openai/human-eval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
30_seconds_of_python_problem.jsonl
159 lines (159 loc) · 49.4 KB
/
30_seconds_of_python_problem.jsonl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{"task_id":"task/1","prompt":"def index_of_all(lst, value):","canonical_solution":" return [i for i, x in enumerate(lst) if x == value]","entry_point":"index_of_all","test":"def check(candidate):\n assert candidate([1, 2, 1, 4, 5, 1], 1) == [0, 2, 5]\n assert candidate([1, 2, 3, 4], 6) == []\n"}
{"task_id":"task/2","prompt":"def head(lst):","canonical_solution":" return lst[0]","entry_point":"head","test":"def check(candidate):\n assert candidate([1, 2, 3]) == 1\n"}
{"task_id":"task/3","prompt":"def max_n(lst, n = 1):","canonical_solution":" return sorted(lst, reverse = True)[:n]","entry_point":"max_n","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [3]\n assert candidate([1, 2, 3], 2) == [3, 2]\n"}
{"task_id":"task/4","prompt":"from datetime import datetime\n\ndef to_iso_date(d):","canonical_solution":" return d.isoformat()","entry_point":"to_iso_date","test":"def check(candidate):\n from datetime import datetime\n \n assert candidate(datetime(2020, 10, 25)) == 2020-10-25T00:00:00\n"}
{"task_id":"task/5","prompt":"def median(list):","canonical_solution":" list.sort()\n list_length = len(list)\n if list_length % 2 == 0:\n return (list[int(list_length / 2) - 1] + list[int(list_length / 2)]) / 2\n return float(list[int(list_length / 2)])","entry_point":"median","test":"def check(candidate):\n assert candidate([1, 2, 3]) == 2.0\n assert candidate([1, 2, 3, 4]) == 2.5\n"}
{"task_id":"task/6","prompt":"def longest_item(*args):","canonical_solution":" return max(args, key = len)","entry_point":"longest_item","test":"def check(candidate):\n assert candidate('this', 'is', 'a', 'testcase') == 'testcase'\n assert candidate([1, 2, 3], [1, 2], [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate([1, 2, 3], 'foobar') == 'foobar'\n"}
{"task_id":"task/7","prompt":"from itertools import chain, combinations\n\ndef powerset(iterable):","canonical_solution":" s = list(iterable)\n return list(chain.from_iterable(combinations(s, r) for r in range(len(s)+1)))","entry_point":"powerset","test":"def check(candidate):\n assert candidate([1, 2]) == [(), (1,), (2,), (1, 2)]\n"}
{"task_id":"task/8","prompt":"def find_index_of_all(lst, fn):","canonical_solution":" return [i for i, x in enumerate(lst) if fn(x)]","entry_point":"find_index_of_all","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], lambda n: n % 2 == 1) == [0, 2]\n"}
{"task_id":"task/9","prompt":"def take(itr, n = 1):","canonical_solution":" return itr[:n]","entry_point":"take","test":"def check(candidate):\n assert candidate([1, 2, 3], 5) == [1, 2, 3]\n assert candidate([1, 2, 3], 0) == []\n"}
{"task_id":"task/10","prompt":"def last(lst):","canonical_solution":" return lst[-1]","entry_point":"last","test":"def check(candidate):\n assert candidate([1, 2, 3]) == 3\n"}
{"task_id":"task/11","prompt":"from time import sleep\n\ndef delay(fn, ms, *args):","canonical_solution":" sleep(ms / 1000)\n return fn(*args)","entry_point":"delay","test":"def check(candidate):\n assert candidate(lambda x: print(x), 1000, 'later') == prints 'later' after one second\n"}
{"task_id":"task/12","prompt":"from functools import partial\n\ndef curry(fn, *args):","canonical_solution":" return partial(fn, *args)","entry_point":"curry","test":"def check(candidate):\n add = lambda x, y: x + y\n add10 = curry(add, 10)\n assert add10(20) == 30\n"}
{"task_id":"task/13","prompt":"def find(lst, fn):","canonical_solution":" return next(x for x in lst if fn(x))","entry_point":"find","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], lambda n: n % 2 == 1) == 1\n"}
{"task_id":"task/14","prompt":"def capitalize_every_word(s):","canonical_solution":" return s.title()","entry_point":"capitalize_every_word","test":"def check(candidate):\n assert candidate('hello world!') == 'Hello World!'\n"}
{"task_id":"task/15","prompt":"from math import sqrt\n\ndef is_prime(n):","canonical_solution":" if n <= 1 or (n % 2 == 0 and n > 2): \n return False\n return all(n % i for i in range(3, int(sqrt(n)) + 1, 2))","entry_point":"is_prime","test":"def check(candidate):\n assert candidate(11) == True\n"}
{"task_id":"task/16","prompt":"def includes_all(lst, values):","canonical_solution":" for v in values:\n if v not in lst:\n return False\n return True","entry_point":"includes_all","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], [1, 4]) == True\n assert candidate([1, 2, 3, 4], [1, 5]) == False\n"}
{"task_id":"task/17","prompt":"from datetime import datetime\n\ndef is_weekend(d = datetime.today()):","canonical_solution":" return d.weekday() > 4","entry_point":"is_weekend","test":"def check(candidate):\n from datetime import date\n \n assert candidate(date(2020, 10, 25)) == True\n assert candidate(date(2020, 10, 28)) == False\n"}
{"task_id":"task/18","prompt":"def spread(arg):","canonical_solution":" ret = []\n for i in arg:\n ret.extend(i) if isinstance(i, list) else ret.append(i)\n return ret","entry_point":"spread","test":"def check(candidate):\n assert candidate([1, 2, 3, [4, 5, 6], [7], 8, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n"}
{"task_id":"task/19","prompt":"from math import copysign\n\ndef reverse_number(n):","canonical_solution":" return copysign(float(str(n)[::-1].replace('-', '')), n)","entry_point":"reverse_number","test":"def check(candidate):\n assert candidate(981) == 189\n assert candidate(-500) == -5\n assert candidate(73.6) == 6.37\n assert candidate(-5.23) == -32.5\n"}
{"task_id":"task/20","prompt":"import re\n\ndef words(s, pattern = '[a-zA-Z-]+'):","canonical_solution":" return re.findall(pattern, s)","entry_point":"words","test":"def check(candidate):\n assert candidate('I love Python!!') == ['I', 'love', 'Python']\n assert candidate('python, javaScript & coffee') == ['python', 'javaScript', 'coffee']\n words('build -q --out one-item', r'\\b[a-zA-Z-]+\\b')\n assert candidate('build -q --out one-item', r'\\b[a-zA-Z-]+\\b') == ['build', 'q', 'out', 'one-item']\n"}
{"task_id":"task/21","prompt":"from random import choice\n\ndef sample(lst):","canonical_solution":" return choice(lst)","entry_point":"sample","test":"def check(candidate):\n assert candidate([3, 7, 9, 11]) == 9\n"}
{"task_id":"task/22","prompt":"from datetime import timedelta, date\n\ndef days_ago(n):","canonical_solution":" return date.today() - timedelta(n)","entry_point":"days_ago","test":"def check(candidate):\n assert candidate(5) == date(2020, 10, 23)\n"}
{"task_id":"task/23","prompt":"def key_in_dict(d, key):","canonical_solution":" return (key in d)","entry_point":"key_in_dict","test":"def check(candidate):\n d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}\n assert candidate(d, 'three') == True\n"}
{"task_id":"task/24","prompt":"def factorial(num):","canonical_solution":" if not ((num >= 0) and (num % 1 == 0)):\n raise Exception(\"Number can't be floating point or negative.\")\n return 1 if num == 0 else num * factorial(num - 1)","entry_point":"factorial","test":"def check(candidate):\n assert candidate(6) == 720\n"}
{"task_id":"task/25","prompt":"def initial(lst):","canonical_solution":" return lst[:-1]","entry_point":"initial","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [1, 2]\n"}
{"task_id":"task/26","prompt":"from math import floor\n\ndef pad(s, length, char = ' '):","canonical_solution":" return s.rjust(floor((len(s) + length)/2), char).ljust(length, char)","entry_point":"pad","test":"def check(candidate):\n assert candidate('cat', 8) == ' cat '\n assert candidate('42', 6, '0') == '004200'\n assert candidate('foobar', 3) == 'foobar'\n"}
{"task_id":"task/27","prompt":"from math import pi\n\ndef degrees_to_rads(deg):","canonical_solution":" return (deg * pi) / 180.0","entry_point":"degrees_to_rads","test":"def check(candidate):\n assert candidate(180) == ~3.1416\n"}
{"task_id":"task/28","prompt":"from functools import reduce\nfrom math import gcd\n\ndef lcm(numbers):","canonical_solution":" return reduce((lambda x, y: int(x * y / gcd(x, y))), numbers)","entry_point":"lcm","test":"def check(candidate):\n assert candidate([12, 7]) == 84\n assert candidate([1, 3, 4, 5]) == 60\n"}
{"task_id":"task/29","prompt":"def most_frequent(lst):","canonical_solution":" return max(set(lst), key = lst.count)","entry_point":"most_frequent","test":"def check(candidate):\n most_frequent([1, 2, 1, 2, 3, 2, 1, 4, 2]) #2\n"}
{"task_id":"task/30","prompt":"from math import pi\n\ndef rads_to_degrees(rad):","canonical_solution":" return (rad * 180.0) / pi","entry_point":"rads_to_degrees","test":"def check(candidate):\n from math import pi\n \n assert candidate(pi / 2) == 90.0\n"}
{"task_id":"task/31","prompt":"def n_times_string(s, n):","canonical_solution":" return (s * n)","entry_point":"n_times_string","test":"def check(candidate):\n n_times_string('py', 4) #'pypypypy'\n"}
{"task_id":"task/32","prompt":"def map_values(obj, fn):","canonical_solution":" return dict((k, fn(v)) for k, v in obj.items())","entry_point":"map_values","test":"def check(candidate):\n users = {\n 'fred': { 'user': 'fred', 'age': 40 },\n 'pebbles': { 'user': 'pebbles', 'age': 1 }\n }\n assert candidate(users, lambda u : u['age']) == {'fred': 40, 'pebbles': 1}\n"}
{"task_id":"task/33","prompt":"def hex_to_rgb(hex):","canonical_solution":" return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))","entry_point":"hex_to_rgb","test":"def check(candidate):\n assert candidate('FFA501') == (255, 165, 1)\n"}
{"task_id":"task/34","prompt":"from copy import deepcopy\nfrom random import randint\n\ndef shuffle(lst):","canonical_solution":" temp_lst = deepcopy(lst)\n m = len(temp_lst)\n while (m):\n m -= 1\n i = randint(0, m)\n temp_lst[m], temp_lst[i] = temp_lst[i], temp_lst[m]\n return temp_lst","entry_point":"shuffle","test":"def check(candidate):\n foo = [1, 2, 3]\n assert candidate(foo) == [2, 3, 1], foo = [1, 2, 3]\n"}
{"task_id":"task/35","prompt":"def find_index(lst, fn):","canonical_solution":" return next(i for i, x in enumerate(lst) if fn(x))","entry_point":"find_index","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], lambda n: n % 2 == 1) == 0\n"}
{"task_id":"task/36","prompt":"def num_to_range(num, inMin, inMax, outMin, outMax):","canonical_solution":" return outMin + (float(num - inMin) / float(inMax - inMin) * (outMax\n - outMin))","entry_point":"num_to_range","test":"def check(candidate):\n assert candidate(5, 0, 10, 0, 100) == 50.0\n"}
{"task_id":"task/37","prompt":"def transpose(lst):","canonical_solution":" return list(zip(*lst))","entry_point":"transpose","test":"def check(candidate):\n transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])\n assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == [(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)]\n"}
{"task_id":"task/38","prompt":"def is_even(num):","canonical_solution":" return num % 2 == 0","entry_point":"is_even","test":"def check(candidate):\n assert candidate(3) == False\n"}
{"task_id":"task/39","prompt":"def max_element_index(arr):","canonical_solution":" return arr.index(max(arr))","entry_point":"max_element_index","test":"def check(candidate):\n assert candidate([5, 8, 9, 7, 10, 3, 0]) == 4\n"}
{"task_id":"task/40","prompt":"def min_n(lst, n = 1):","canonical_solution":" return sorted(lst, reverse = False)[:n]","entry_point":"min_n","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [1]\n assert candidate([1, 2, 3], 2) == [1, 2]\n"}
{"task_id":"task/41","prompt":"def take_right(itr, n = 1):","canonical_solution":" return itr[-n:]","entry_point":"take_right","test":"def check(candidate):\n assert candidate([1, 2, 3], 2) == [2, 3]\n assert candidate([1, 2, 3]) == [3]\n"}
{"task_id":"task/42","prompt":"from collections import Counter\n\ndef filter_unique(lst):","canonical_solution":" return [item for item, count in Counter(lst).items() if count > 1]","entry_point":"filter_unique","test":"def check(candidate):\n assert candidate([1, 2, 2, 3, 4, 4, 5]) == [2, 4]\n"}
{"task_id":"task/43","prompt":"def arithmetic_progression(n, lim):","canonical_solution":" return list(range(n, lim + 1, n))","entry_point":"arithmetic_progression","test":"def check(candidate):\n assert candidate(5, 25) == [5, 10, 15, 20, 25]\n"}
{"task_id":"task/44","prompt":"def merge_dictionaries(*dicts):","canonical_solution":" res = dict()\n for d in dicts:\n res.update(d)\n return res","entry_point":"merge_dictionaries","test":"def check(candidate):\n ages_one = {\n 'Peter': 10,\n 'Isabel': 11,\n }\n ages_two = {\n 'Anna': 9\n }\n merge_dictionaries(ages_one, ages_two)\n assert candidate(ages_one, ages_two) == { 'Peter': 10, 'Isabel': 11, 'Anna': 9 }\n"}
{"task_id":"task/45","prompt":"def sort_by_indexes(lst, indexes, reverse=False):","canonical_solution":" return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \\\n x[0], reverse=reverse)]","entry_point":"sort_by_indexes","test":"def check(candidate):\n a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']\n b = [3, 2, 6, 4, 1, 5]\n assert candidate(a, b) == ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']\n sort_by_indexes(a, b, True)\n assert candidate(a, b, True) == ['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples']\n"}
{"task_id":"task/46","prompt":"from functools import reduce \nfrom operator import getitem\n\ndef get(d, selectors):","canonical_solution":" return reduce(getitem, selectors, d)","entry_point":"get","test":"def check(candidate):\n users = {\n 'freddy': {\n 'name': {\n 'first': 'fred',\n 'last': 'smith' \n },\n 'postIds': [1, 2, 3]\n }\n }\n assert candidate(users, ['freddy', 'name', 'last']) == 'smith'\n assert candidate(users, ['freddy', 'postIds', 1]) == 2\n"}
{"task_id":"task/47","prompt":"def bifurcate_by(lst, fn):","canonical_solution":" return [\n [x for x in lst if fn(x)],\n [x for x in lst if not fn(x)]\n ]","entry_point":"bifurcate_by","test":"def check(candidate):\n bifurcate_by(['beep', 'boop', 'foo', 'bar'], lambda x: x[0] == 'b')\n assert candidate(['beep', 'boop', 'foo', 'bar'], lambda x: x[0] == 'b') == [ ['beep', 'boop', 'bar'], ['foo'] ]\n"}
{"task_id":"task/48","prompt":"def fibonacci(n):","canonical_solution":" if n <= 0:\n return [0]\n sequence = [0, 1]\n while len(sequence) <= n:\n next_value = sequence[len(sequence) - 1] + sequence[len(sequence) - 2]\n sequence.append(next_value)\n return sequence","entry_point":"fibonacci","test":"def check(candidate):\n assert candidate(7) == [0, 1, 1, 2, 3, 5, 8, 13]\n"}
{"task_id":"task/49","prompt":"def invert_dictionary(obj):","canonical_solution":" return { value: key for key, value in obj.items() }","entry_point":"invert_dictionary","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 11,\n 'Anna': 9,\n }\n assert candidate(ages) == { 10: 'Peter', 11: 'Isabel', 9: 'Anna' }\n"}
{"task_id":"task/50","prompt":"from re import sub\n\ndef camel(s):","canonical_solution":" s = sub(r\"(_|-)+\", \" \", s).title().replace(\" \", \"\")\n return ''.join([s[0].lower(), s[1:]])","entry_point":"camel","test":"def check(candidate):\n assert candidate('some_database_field_name') == 'someDatabaseFieldName'\n camel('Some label that needs to be camelized')\n assert candidate('Some label that needs to be candidateized') == 'someLabelThatNeedsToBeCamelized'\n assert candidate('some-javascript-property') == 'someJavascriptProperty'\n camel('some-mixed_string with spaces_underscores-and-hyphens')\n assert candidate('some-mixed_string with spaces_underscores-and-hyphens') == 'someMixedStringWithSpacesUnderscoresAndHyphens'\n"}
{"task_id":"task/51","prompt":"def key_of_min(d):","canonical_solution":" return min(d, key = d.get)","entry_point":"key_of_min","test":"def check(candidate):\n assert candidate({'a':4, 'b':0, 'c':13}) == b\n"}
{"task_id":"task/52","prompt":"def capitalize(s, lower_rest = False):","canonical_solution":" return ''.join([s[:1].upper(), (s[1:].lower() if lower_rest else s[1:])])","entry_point":"capitalize","test":"def check(candidate):\n assert candidate('fooBar') == 'FooBar'\n assert candidate('fooBar', True) == 'Foobar'\n"}
{"task_id":"task/53","prompt":"def celsius_to_fahrenheit(degrees):","canonical_solution":" return ((degrees * 1.8) + 32)","entry_point":"celsius_to_fahrenheit","test":"def check(candidate):\n assert candidate(180) == 356.0\n"}
{"task_id":"task/54","prompt":"def every_nth(lst, nth):","canonical_solution":" return lst[nth - 1::nth]","entry_point":"every_nth","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5, 6], 2) == [ 2, 4, 6 ]\n"}
{"task_id":"task/55","prompt":"def union(a, b):","canonical_solution":" return list(set(a + b))","entry_point":"union","test":"def check(candidate):\n assert candidate([1, 2, 3], [4, 3, 2]) == [1, 2, 3, 4]\n"}
{"task_id":"task/56","prompt":"def drop(a, n = 1):","canonical_solution":" return a[n:]","entry_point":"drop","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [2, 3]\n assert candidate([1, 2, 3], 2) == [3]\n assert candidate([1, 2, 3], 42) == []\n"}
{"task_id":"task/57","prompt":"from collections import defaultdict\n\ndef frequencies(lst):","canonical_solution":" freq = defaultdict(int)\n for val in lst:\n freq[val] += 1\n return dict(freq)","entry_point":"frequencies","test":"def check(candidate):\n assert candidate(['a', 'b', 'a', 'c', 'a', 'a', 'b']) == { 'a': 4, 'b': 2, 'c': 1 }\n"}
{"task_id":"task/58","prompt":"def initialize_list_with_range(end, start = 0, step = 1):","canonical_solution":" return list(range(start, end + 1, step))","entry_point":"initialize_list_with_range","test":"def check(candidate):\n assert candidate(5) == [0, 1, 2, 3, 4, 5]\n assert candidate(7, 3) == [3, 4, 5, 6, 7]\n assert candidate(9, 0, 2) == [0, 2, 4, 6, 8]\n"}
{"task_id":"task/59","prompt":"from itertools import accumulate\n\ndef cumsum(lst):","canonical_solution":" return list(accumulate(lst))","entry_point":"cumsum","test":"def check(candidate):\n assert candidate(range(0, 15, 3)) == [0, 3, 9, 18, 30]\n"}
{"task_id":"task/60","prompt":"from math import ceil\n\ndef months_diff(start, end):","canonical_solution":" return ceil((end - start).days / 30)","entry_point":"months_diff","test":"def check(candidate):\n from datetime import date\n \n assert candidate(date(2020, 10, 28), date(2020, 11, 25)) == 1\n"}
{"task_id":"task/61","prompt":"from collections import defaultdict\n\ndef collect_dictionary(obj):","canonical_solution":" inv_obj = defaultdict(list)\n for key, value in obj.items():\n inv_obj[value].append(key)\n return dict(inv_obj)","entry_point":"collect_dictionary","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 10,\n 'Anna': 9,\n }\n assert candidate(ages) == { 10: ['Peter', 'Isabel'], 9: ['Anna'] }\n"}
{"task_id":"task/62","prompt":"from math import comb\n\ndef binomial_coefficient(n, k):","canonical_solution":" return comb(n, k)","entry_point":"binomial_coefficient","test":"def check(candidate):\n assert candidate(8, 2) == 28\n"}
{"task_id":"task/63","prompt":"def find_keys(dict, val):","canonical_solution":" return list(key for key, value in dict.items() if value == val)","entry_point":"find_keys","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 11,\n 'Anna': 10,\n }\n assert candidate(ages, 10) == [ 'Peter', 'Anna' ]\n"}
{"task_id":"task/64","prompt":"def when(predicate, when_true):","canonical_solution":" return lambda x: when_true(x) if predicate(x) else x","entry_point":"when","test":"def check(candidate):\n double_even_numbers = when(lambda x: x % 2 == 0, lambda x : x * 2)\n assert double_even_numbers(2) == 4\n assert double_even_numbers(1) == 1\n"}
{"task_id":"task/65","prompt":"from math import ceil\n\ndef chunk_into_n(lst, n):","canonical_solution":" size = ceil(len(lst) / n)\n return list(\n map(lambda x: lst[x * size:x * size + size],\n list(range(n)))\n )","entry_point":"chunk_into_n","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5, 6, 7], 4) == [[1, 2], [3, 4], [5, 6], [7]]\n"}
{"task_id":"task/66","prompt":"def km_to_miles(km):","canonical_solution":" return km * 0.621371","entry_point":"km_to_miles","test":"def check(candidate):\n assert candidate(8.1) == 5.0331051\n"}
{"task_id":"task/67","prompt":"def max_by(lst, fn):","canonical_solution":" return max(map(fn, lst))","entry_point":"max_by","test":"def check(candidate):\n assert candidate([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda v : v['n']) == 8\n"}
{"task_id":"task/68","prompt":"def min_element_index(arr):","canonical_solution":" return arr.index(min(arr))","entry_point":"min_element_index","test":"def check(candidate):\n assert candidate([3, 5, 2, 6, 10, 7, 9]) == 2\n"}
{"task_id":"task/69","prompt":"def initialize_2d_list(w, h, val = None):","canonical_solution":" return [[val for x in range(w)] for y in range(h)]","entry_point":"initialize_2d_list","test":"def check(candidate):\n assert candidate(2, 2, 0) == [[0, 0], [0, 0]]\n"}
{"task_id":"task/70","prompt":"def dict_to_list(d):","canonical_solution":" return list(d.items())","entry_point":"dict_to_list","test":"def check(candidate):\n d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}\n dict_to_list(d)\n assert candidate(d) == [('one', 1), ('three', 3), ('five', 5), ('two', 2), ('four', 4)]\n"}
{"task_id":"task/71","prompt":"def average(*args):","canonical_solution":" return sum(args, 0.0) / len(args)","entry_point":"average","test":"def check(candidate):\n assert candidate(*[1, 2, 3]) == 2.0\n assert candidate(1, 2, 3) == 2.0\n"}
{"task_id":"task/72","prompt":"def intersection(a, b):","canonical_solution":" _a, _b = set(a), set(b)\n return list(_a & _b)","entry_point":"intersection","test":"def check(candidate):\n assert candidate([1, 2, 3], [4, 3, 2]) == [2, 3]\n"}
{"task_id":"task/73","prompt":"def hamming_distance(a, b):","canonical_solution":" return bin(a ^ b).count('1')","entry_point":"hamming_distance","test":"def check(candidate):\n assert candidate(2, 3) == 1\n"}
{"task_id":"task/74","prompt":"def digitize(n):","canonical_solution":" return list(map(int, str(n)))","entry_point":"digitize","test":"def check(candidate):\n assert candidate(123) == [1, 2, 3]\n"}
{"task_id":"task/75","prompt":"def roll(lst, offset):","canonical_solution":" return lst[-offset:] + lst[:-offset]","entry_point":"roll","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3]\n assert candidate([1, 2, 3, 4, 5], -2) == [3, 4, 5, 1, 2]\n"}
{"task_id":"task/76","prompt":"def some(lst, fn = lambda x: x):","canonical_solution":" return any(map(fn, lst))","entry_point":"some","test":"def check(candidate):\n assert candidate([0, 1, 2, 0], lambda x: x >= 2 ) == True\n assert candidate([0, 0, 1, 0]) == True\n"}
{"task_id":"task/77","prompt":"from collections import defaultdict\n\ndef combine_values(*dicts):","canonical_solution":" res = defaultdict(list)\n for d in dicts:\n for key in d:\n res[key].append(d[key])\n return dict(res)","entry_point":"combine_values","test":"def check(candidate):\n d1 = {'a': 1, 'b': 'foo', 'c': 400}\n d2 = {'a': 3, 'b': 200, 'd': 400}\n \n assert candidate(d1, d2) == {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]}\n"}
{"task_id":"task/78","prompt":"def flatten(lst):","canonical_solution":" return [x for y in lst for x in y]","entry_point":"flatten","test":"def check(candidate):\n assert candidate([[1, 2, 3, 4], [5, 6, 7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8]\n"}
{"task_id":"task/79","prompt":"def symmetric_difference_by(a, b, fn):","canonical_solution":" (_a, _b) = (set(map(fn, a)), set(map(fn, b)))\n return [item for item in a if fn(item) not in _b] + [item\n for item in b if fn(item) not in _a]","entry_point":"symmetric_difference_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([2.1, 1.2], [2.3, 3.4], floor) == [1.2, 3.4]\n"}
{"task_id":"task/80","prompt":"def find_last_index(lst, fn):","canonical_solution":" return len(lst) - 1 - next(i for i, x in enumerate(lst[::-1]) if fn(x))","entry_point":"find_last_index","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], lambda n: n % 2 == 1) == 2\n"}
{"task_id":"task/81","prompt":"def weighted_average(nums, weights):","canonical_solution":" return sum(x * y for x, y in zip(nums, weights)) / sum(weights)","entry_point":"weighted_average","test":"def check(candidate):\n assert candidate([1, 2, 3], [0.6, 0.2, 0.3]) == 1.72727\n"}
{"task_id":"task/82","prompt":"def bifurcate(lst, filter):","canonical_solution":" return [\n [x for x, flag in zip(lst, filter) if flag],\n [x for x, flag in zip(lst, filter) if not flag]\n ]","entry_point":"bifurcate","test":"def check(candidate):\n bifurcate(['beep', 'boop', 'foo', 'bar'], [True, True, False, True])\n assert candidate(['beep', 'boop', 'foo', 'bar'], [True, True, False, True]) == [ ['beep', 'boop', 'bar'], ['foo'] ]\n"}
{"task_id":"task/83","prompt":"def all_equal(lst):","canonical_solution":" return len(set(lst)) == 1","entry_point":"all_equal","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5, 6]) == False\n assert candidate([1, 1, 1, 1]) == True\n"}
{"task_id":"task/84","prompt":"def difference(a, b):","canonical_solution":" _b = set(b)\n return [item for item in a if item not in _b]","entry_point":"difference","test":"def check(candidate):\n assert candidate([1, 2, 3], [1, 2, 4]) == [3]\n"}
{"task_id":"task/85","prompt":"from re import sub\n\ndef kebab(s):","canonical_solution":" return '-'.join(\n sub(r\"(\\s|_|-)+\",\" \",\n sub(r\"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+\",\n lambda mo: ' ' + mo.group(0).lower(), s)).split())","entry_point":"kebab","test":"def check(candidate):\n assert candidate('camelCase') == 'camel-case'\n assert candidate('some text') == 'some-text'\n kebab('some-mixed_string With spaces_underscores-and-hyphens')\n assert candidate('some-mixed_string With spaces_underscores-and-hyphens') == 'some-mixed-string-with-spaces-underscores-and-hyphens'\n assert candidate('AllThe-small Things') == 'all-the-small-things'\n"}
{"task_id":"task/86","prompt":"def miles_to_km(miles):","canonical_solution":" return miles * 1.609344","entry_point":"miles_to_km","test":"def check(candidate):\n assert candidate(5.03) == 8.09500032\n"}
{"task_id":"task/87","prompt":"def sum_of_powers(end, power = 2, start = 1):","canonical_solution":" return sum([(i) ** power for i in range(start, end + 1)])","entry_point":"sum_of_powers","test":"def check(candidate):\n assert candidate(10) == 385\n assert candidate(10, 3) == 3025\n assert candidate(10, 3, 5) == 2925\n"}
{"task_id":"task/88","prompt":"from functools import reduce\n\ndef compose(*fns):","canonical_solution":" return reduce(lambda f, g: lambda *args: f(g(*args)), fns)","entry_point":"compose","test":"def check(candidate):\n add5 = lambda x: x + 5\n multiply = lambda x, y: x * y\n multiply_and_add_5 = compose(add5, multiply)\n assert multiply_and_add_5(5, 2) == 15\n"}
{"task_id":"task/89","prompt":"def similarity(a, b):","canonical_solution":" return [item for item in a if item in b]","entry_point":"similarity","test":"def check(candidate):\n assert candidate([1, 2, 3], [1, 2, 4]) == [1, 2]\n"}
{"task_id":"task/90","prompt":"def have_same_contents(a, b):","canonical_solution":" for v in set(a + b):\n if a.count(v) != b.count(v):\n return False\n return True","entry_point":"have_same_contents","test":"def check(candidate):\n assert candidate([1, 2, 4], [2, 4, 1]) == True\n"}
{"task_id":"task/91","prompt":"from datetime import timedelta, date\n\ndef days_from_now(n):","canonical_solution":" return date.today() + timedelta(n)","entry_point":"days_from_now","test":"def check(candidate):\n assert candidate(5) == date(2020, 11, 02)\n"}
{"task_id":"task/92","prompt":"def cast_list(val):","canonical_solution":" return list(val) if isinstance(val, (tuple, list, set, dict)) else [val]","entry_point":"cast_list","test":"def check(candidate):\n assert candidate('foo') == ['foo']\n assert candidate([1]) == [1]\n assert candidate(('foo', 'bar')) == ['foo', 'bar']\n"}
{"task_id":"task/93","prompt":"def sort_dict_by_value(d, reverse = False):","canonical_solution":" return dict(sorted(d.items(), key = lambda x: x[1], reverse = reverse))","entry_point":"sort_dict_by_value","test":"def check(candidate):\n d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}\n assert candidate(d) == {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}\n sort_dict_by_value(d, True)\n assert candidate(d, True) == {'five': 5, 'four': 4, 'three': 3, 'two': 2, 'one': 1}\n"}
{"task_id":"task/94","prompt":"import re\n\ndef slugify(s):","canonical_solution":" s = s.lower().strip()\n s = re.sub(r'[^\\w\\s-]', '', s)\n s = re.sub(r'[\\s_-]+', '-', s)\n s = re.sub(r'^-+|-+$', '', s)\n return s","entry_point":"slugify","test":"def check(candidate):\n assert candidate('Hello World!') == 'hello-world'\n"}
{"task_id":"task/95","prompt":"def to_roman_numeral(num):","canonical_solution":" lookup = [\n (1000, 'M'),\n (900, 'CM'),\n (500, 'D'),\n (400, 'CD'),\n (100, 'C'),\n (90, 'XC'),\n (50, 'L'),\n (40, 'XL'),\n (10, 'X'),\n (9, 'IX'),\n (5, 'V'),\n (4, 'IV'),\n (1, 'I'),\n ]\n res = ''\n for (n, roman) in lookup:\n (d, num) = divmod(num, n)\n res += roman * d\n return res","entry_point":"to_roman_numeral","test":"def check(candidate):\n assert candidate(3) == 'III'\n assert candidate(11) == 'XI'\n assert candidate(1998) == 'MCMXCVIII'\n"}
{"task_id":"task/96","prompt":"def check_prop(fn, prop):","canonical_solution":" return lambda obj: fn(obj[prop])","entry_point":"check_prop","test":"def check(candidate):\n check_age = check_prop(lambda x: x >= 18, 'age')\n user = {'name': 'Mark', 'age': 18}\n assert check_age(user) == True\n"}
{"task_id":"task/97","prompt":"def count_occurrences(lst, val):","canonical_solution":" return lst.count(val)","entry_point":"count_occurrences","test":"def check(candidate):\n assert candidate([1, 1, 2, 1, 2, 3], 1) == 3\n"}
{"task_id":"task/98","prompt":"from collections import Counter\n\ndef find_parity_outliers(nums):","canonical_solution":" return [\n x for x in nums\n if x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]\n ]","entry_point":"find_parity_outliers","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 6]) == [1, 3]\n"}
{"task_id":"task/99","prompt":"def to_dictionary(keys, values):","canonical_solution":" return dict(zip(keys, values))","entry_point":"to_dictionary","test":"def check(candidate):\n assert candidate(['a', 'b'], [1, 2]) == { a: 1, b: 2 }\n"}
{"task_id":"task/100","prompt":"from math import floor, log\n\ndef geometric_progression(end, start=1, step=2):","canonical_solution":" return [start * step ** i for i in range(floor(log(end / start)\n / log(step)) + 1)]","entry_point":"geometric_progression","test":"def check(candidate):\n assert candidate(256) == [1, 2, 4, 8, 16, 32, 64, 128, 256]\n assert candidate(256, 3) == [3, 6, 12, 24, 48, 96, 192]\n assert candidate(256, 1, 4) == [1, 4, 16, 64, 256]\n"}
{"task_id":"task/101","prompt":"def find_last(lst, fn):","canonical_solution":" return next(x for x in lst[::-1] if fn(x))","entry_point":"find_last","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], lambda n: n % 2 == 1) == 3\n"}
{"task_id":"task/102","prompt":"def sort_dict_by_key(d, reverse = False):","canonical_solution":" return dict(sorted(d.items(), reverse = reverse))","entry_point":"sort_dict_by_key","test":"def check(candidate):\n d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}\n assert candidate(d) == {'five': 5, 'four': 4, 'one': 1, 'three': 3, 'two': 2}\n sort_dict_by_key(d, True)\n assert candidate(d, True) == {'two': 2, 'three': 3, 'one': 1, 'four': 4, 'five': 5}\n"}
{"task_id":"task/103","prompt":"def split_lines(s):","canonical_solution":" return s.split('\\n')","entry_point":"split_lines","test":"def check(candidate):\n split_lines('This\\nis a\\nmultiline\\nstring.\\n')\n assert candidate('This\\nis a\\nmultiline\\nstring.\\n') == ['This', 'is a', 'multiline', 'string.' , '']\n"}
{"task_id":"task/104","prompt":"def includes_any(lst, values):","canonical_solution":" for v in values:\n if v in lst:\n return True\n return False","entry_point":"includes_any","test":"def check(candidate):\n assert candidate([1, 2, 3, 4], [2, 9]) == True\n assert candidate([1, 2, 3, 4], [8, 9]) == False\n"}
{"task_id":"task/105","prompt":"def merge(*args, fill_value = None):","canonical_solution":" max_length = max([len(lst) for lst in args])\n result = []\n for i in range(max_length):\n result.append([\n args[k][i] if i < len(args[k]) else fill_value for k in range(len(args))\n ])\n return result","entry_point":"merge","test":"def check(candidate):\n assert candidate(['a', 'b'], [1, 2], [True, False]) == [['a', 1, True], ['b', 2, False]]\n assert candidate(['a'], [1, 2], [True, False]) == [['a', 1, True], [None, 2, False]]\n merge(['a'], [1, 2], [True, False], fill_value = '_')\n assert candidate(['a'], [1, 2], [True, False], fill_value = '_') == [['a', 1, True], ['_', 2, False]]\n"}
{"task_id":"task/106","prompt":"def min_by(lst, fn):","canonical_solution":" return min(map(fn, lst))","entry_point":"min_by","test":"def check(candidate):\n assert candidate([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda v : v['n']) == 2\n"}
{"task_id":"task/107","prompt":"from datetime import datetime, timedelta\n\ndef add_days(n, d = datetime.today()):","canonical_solution":" return d + timedelta(n)","entry_point":"add_days","test":"def check(candidate):\n from datetime import date\n \n assert candidate(5, date(2020, 10, 25)) == date(2020, 10, 30)\n assert candidate(-5, date(2020, 10, 25)) == date(2020, 10, 20)\n"}
{"task_id":"task/108","prompt":"from re import sub\n\ndef palindrome(s):","canonical_solution":" s = sub('[\\W_]', '', s.lower())\n return s == s[::-1]","entry_point":"palindrome","test":"def check(candidate):\n assert candidate('taco cat') == True\n"}
{"task_id":"task/109","prompt":"def none(lst, fn = lambda x: x):","canonical_solution":" return all(not fn(x) for x in lst)","entry_point":"none","test":"def check(candidate):\n assert candidate([0, 1, 2, 0], lambda x: x >= 2 ) == False\n assert candidate([0, 0, 0]) == True\n"}
{"task_id":"task/110","prompt":"def tail(lst):","canonical_solution":" return lst[1:] if len(lst) > 1 else lst","entry_point":"tail","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [2, 3]\n assert candidate([1]) == [1]\n"}
{"task_id":"task/111","prompt":"def has_duplicates(lst):","canonical_solution":" return len(lst) != len(set(lst))","entry_point":"has_duplicates","test":"def check(candidate):\n x = [1, 2, 3, 4, 5, 5]\n y = [1, 2, 3, 4, 5]\n assert candidate(x) == True\n assert candidate(y) == False\n"}
{"task_id":"task/112","prompt":"def map_dictionary(itr, fn):","canonical_solution":" return dict(zip(itr, map(fn, itr)))","entry_point":"map_dictionary","test":"def check(candidate):\n assert candidate([1, 2, 3], lambda x: x * x) == { 1: 1, 2: 4, 3: 9 }\n"}
{"task_id":"task/113","prompt":"from collections import defaultdict\n\ndef count_by(lst, fn = lambda x: x):","canonical_solution":" count = defaultdict(int)\n for val in map(fn, lst):\n count[val] += 1\n return dict(count)","entry_point":"count_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([6.1, 4.2, 6.3], floor) == {6: 2, 4: 1}\n assert candidate(['one', 'two', 'three'], len) == {3: 2, 5: 1}\n"}
{"task_id":"task/114","prompt":"def difference_by(a, b, fn):","canonical_solution":" _b = set(map(fn, b))\n return [item for item in a if fn(item) not in _b]","entry_point":"difference_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([2.1, 1.2], [2.3, 3.4], floor) == [1.2]\n difference_by([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], lambda v : v['x'])\n assert candidate([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], lambda v : v['x']) == [ { x: 2 } ]\n"}
{"task_id":"task/115","prompt":"from datetime import datetime\n\ndef from_iso_date(d):","canonical_solution":" return datetime.fromisoformat(d)","entry_point":"from_iso_date","test":"def check(candidate):\n assert candidate('2020-10-28T12:30:59.000000') == 2020-10-28 12:30:59\n"}
{"task_id":"task/116","prompt":"from collections import Counter\n\ndef filter_non_unique(lst):","canonical_solution":" return [item for item, count in Counter(lst).items() if count == 1]","entry_point":"filter_non_unique","test":"def check(candidate):\n assert candidate([1, 2, 2, 3, 4, 4, 5]) == [1, 3, 5]\n"}
{"task_id":"task/117","prompt":"def symmetric_difference(a, b):","canonical_solution":" (_a, _b) = (set(a), set(b))\n return [item for item in a if item not in _b] + [item for item in b\n if item not in _a]","entry_point":"symmetric_difference","test":"def check(candidate):\n assert candidate([1, 2, 3], [1, 2, 4]) == [3, 4]\n"}
{"task_id":"task/118","prompt":"from re import sub\n\ndef snake(s):","canonical_solution":" return '_'.join(\n sub('([A-Z][a-z]+)', r' \\1',\n sub('([A-Z]+)', r' \\1',\n s.replace('-', ' '))).split()).lower()","entry_point":"snake","test":"def check(candidate):\n assert candidate('camelCase') == 'camel_case'\n assert candidate('some text') == 'some_text'\n snake('some-mixed_string With spaces_underscores-and-hyphens')\n assert candidate('some-mixed_string With spaces_underscores-and-hyphens') == 'some_mixed_string_with_spaces_underscores_and_hyphens'\n assert candidate('AllThe-small Things') == 'all_the_small_things'\n"}
{"task_id":"task/119","prompt":"def keys_only(flat_dict):","canonical_solution":" return list(flat_dict.keys())","entry_point":"keys_only","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 11,\n 'Anna': 9,\n }\n assert candidate(ages) == ['Peter', 'Isabel', 'Anna']\n"}
{"task_id":"task/120","prompt":"def is_odd(num):","canonical_solution":" return num % 2 != 0","entry_point":"is_odd","test":"def check(candidate):\n assert candidate(3) == True\n"}
{"task_id":"task/121","prompt":"from collections import defaultdict\n\ndef group_by(lst, fn):","canonical_solution":" d = defaultdict(list)\n for el in lst:\n d[fn(el)].append(el)\n return dict(d)","entry_point":"group_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([6.1, 4.2, 6.3], floor) == {4: [4.2], 6: [6.1, 6.3]}\n assert candidate(['one', 'two', 'three'], len) == {3: ['one', 'two'], 5: ['three']}\n"}
{"task_id":"task/122","prompt":"def to_binary(n):","canonical_solution":" return bin(n)","entry_point":"to_binary","test":"def check(candidate):\n assert candidate(100) == 0b1100100\n"}
{"task_id":"task/123","prompt":"def compact(lst):","canonical_solution":" return list(filter(None, lst))","entry_point":"compact","test":"def check(candidate):\n assert candidate([0, 1, False, 2, '', 3, 'a', 's', 34]) == [ 1, 2, 3, 'a', 's', 34 ]\n"}
{"task_id":"task/124","prompt":"def in_range(n, start, end = 0):","canonical_solution":" return start <= n <= end if end >= start else end <= n <= start","entry_point":"in_range","test":"def check(candidate):\n assert candidate(3, 2, 5) == True\n assert candidate(3, 4) == True\n assert candidate(2, 3, 5) == False\n assert candidate(3, 2) == False\n"}
{"task_id":"task/125","prompt":"from datetime import timedelta, date\n\ndef daterange(start, end):","canonical_solution":" return [start + timedelta(n) for n in range(int((end - start).days))]","entry_point":"daterange","test":"def check(candidate):\n from datetime import date\n \n daterange(date(2020, 10, 1), date(2020, 10, 5))\n assert candidate(date(2020, 10, 1), date(2020, 10, 5)) == [date(2020, 10, 1), date(2020, 10, 2), date(2020, 10, 3), date(2020, 10, 4)]\n"}
{"task_id":"task/126","prompt":"from math import ceil\n\ndef chunk(lst, size):","canonical_solution":" return list(\n map(lambda x: lst[x * size:x * size + size],\n list(range(ceil(len(lst) / size)))))","entry_point":"chunk","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5], 2) == [[1, 2], [3, 4], [5]]\n"}
{"task_id":"task/127","prompt":"from collections.abc import Iterable\n\ndef deep_flatten(lst):","canonical_solution":" return ([a for i in lst for a in\n deep_flatten(i)] if isinstance(lst, Iterable) else [lst])","entry_point":"deep_flatten","test":"def check(candidate):\n assert candidate([1, [2], [[3], 4], 5]) == [1, 2, 3, 4, 5]\n"}
{"task_id":"task/128","prompt":"def initialize_list_with_values(n, val = 0):","canonical_solution":" return [val for x in range(n)]","entry_point":"initialize_list_with_values","test":"def check(candidate):\n assert candidate(5, 2) == [2, 2, 2, 2, 2]\n"}
{"task_id":"task/129","prompt":"def average_by(lst, fn = lambda x: x):","canonical_solution":" return sum(map(fn, lst), 0.0) / len(lst)","entry_point":"average_by","test":"def check(candidate):\n average_by([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda x: x['n'])\n assert candidate([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda x: x['n']) == 5.0\n"}
{"task_id":"task/130","prompt":"def key_of_max(d):","canonical_solution":" return max(d, key = d.get)","entry_point":"key_of_max","test":"def check(candidate):\n assert candidate({'a':4, 'b':0, 'c':13}) == c\n"}
{"task_id":"task/131","prompt":"def offset(lst, offset):","canonical_solution":" return lst[offset:] + lst[:offset]","entry_point":"offset","test":"def check(candidate):\n assert candidate([1, 2, 3, 4, 5], 2) == [3, 4, 5, 1, 2]\n assert candidate([1, 2, 3, 4, 5], -2) == [4, 5, 1, 2, 3]\n"}
{"task_id":"task/132","prompt":"def intersection_by(a, b, fn):","canonical_solution":" _b = set(map(fn, b))\n return [item for item in a if fn(item) in _b]","entry_point":"intersection_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([2.1, 1.2], [2.3, 3.4], floor) == [2.1]\n"}
{"task_id":"task/133","prompt":"def union_by(a, b, fn):","canonical_solution":" _a = set(map(fn, a))\n return list(set(a + [item for item in b if fn(item) not in _a]))","entry_point":"union_by","test":"def check(candidate):\n from math import floor\n \n assert candidate([2.1], [1.2, 2.3], floor) == [2.1, 1.2]\n"}
{"task_id":"task/134","prompt":"def all_unique(lst):","canonical_solution":" return len(lst) == len(set(lst))","entry_point":"all_unique","test":"def check(candidate):\n x = [1, 2, 3, 4, 5, 6]\n y = [1, 2, 2, 3, 4, 5]\n assert candidate(x) == True\n assert candidate(y) == False\n"}
{"task_id":"task/135","prompt":"def pluck(lst, key):","canonical_solution":" return [x.get(key) for x in lst]","entry_point":"pluck","test":"def check(candidate):\n simpsons = [\n { 'name': 'lisa', 'age': 8 },\n { 'name': 'homer', 'age': 36 },\n { 'name': 'marge', 'age': 34 },\n { 'name': 'bart', 'age': 10 }\n ]\n assert candidate(simpsons, 'age') == [8, 36, 34, 10]\n"}
{"task_id":"task/136","prompt":"def for_each(itr, fn):","canonical_solution":" for el in itr:\n fn(el)","entry_point":"for_each","test":"def check(candidate):\n assert candidate([1, 2, 3], print) == 1 2 3\n"}
{"task_id":"task/137","prompt":"def every(lst, fn = lambda x: x):","canonical_solution":" return all(map(fn, lst))","entry_point":"every","test":"def check(candidate):\n assert candidate([4, 2, 3], lambda x: x > 1) == True\n assert candidate([1, 2, 3]) == True\n"}
{"task_id":"task/138","prompt":"def byte_size(s):","canonical_solution":" return len(s.encode('utf-8'))","entry_point":"byte_size","test":"def check(candidate):\n assert candidate('\ud83d\ude00') == 4\n assert candidate('Hello World') == 11\n"}
{"task_id":"task/139","prompt":"def pad_number(n, l):","canonical_solution":" return str(n).zfill(l)","entry_point":"pad_number","test":"def check(candidate):\n assert candidate(1234, 6); == '001234'\n"}
{"task_id":"task/140","prompt":"def for_each_right(itr, fn):","canonical_solution":" for el in itr[::-1]:\n fn(el)","entry_point":"for_each_right","test":"def check(candidate):\n assert candidate([1, 2, 3], print) == 3 2 1\n"}
{"task_id":"task/141","prompt":"from collections import Counter\n\ndef is_anagram(s1, s2):","canonical_solution":" return Counter(\n c.lower() for c in s1 if c.isalnum()\n ) == Counter(\n c.lower() for c in s2 if c.isalnum()\n )","entry_point":"is_anagram","test":"def check(candidate):\n assert candidate('#anagram', 'Nag a ram!') == True\n"}
{"task_id":"task/142","prompt":"def decapitalize(s, upper_rest = False):","canonical_solution":" return ''.join([s[:1].lower(), (s[1:].upper() if upper_rest else s[1:])])","entry_point":"decapitalize","test":"def check(candidate):\n assert candidate('FooBar') == 'fooBar'\n assert candidate('FooBar', True) == 'fOOBAR'\n"}
{"task_id":"task/143","prompt":"def unique_elements(li):","canonical_solution":" return list(set(li))","entry_point":"unique_elements","test":"def check(candidate):\n assert candidate([1, 2, 2, 3, 4, 3]) == [1, 2, 3, 4]\n"}
{"task_id":"task/144","prompt":"def rgb_to_hex(r, g, b):","canonical_solution":" return ('{:02X}' * 3).format(r, g, b)","entry_point":"rgb_to_hex","test":"def check(candidate):\n assert candidate(255, 165, 1) == 'FFA501'\n"}
{"task_id":"task/145","prompt":"def values_only(flat_dict):","canonical_solution":" return list(flat_dict.values())","entry_point":"values_only","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 11,\n 'Anna': 9,\n }\n assert candidate(ages) == [10, 11, 9]\n"}
{"task_id":"task/146","prompt":"def unfold(fn, seed):","canonical_solution":" def fn_generator(val):\n while True: \n val = fn(val[1])\n if val == False: break\n yield val[0]\n return [i for i in fn_generator([None, seed])]","entry_point":"unfold","test":"def check(candidate):\n f = lambda n: False if n > 50 else [-n, n + 10]\n assert candidate(f, 10) == [-10, -20, -30, -40, -50]\n"}
{"task_id":"task/147","prompt":"def reverse(itr):","canonical_solution":" return itr[::-1]","entry_point":"reverse","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [3, 2, 1]\n assert candidate('snippet') == 'teppins'\n"}
{"task_id":"task/148","prompt":"def is_divisible(dividend, divisor):","canonical_solution":" return dividend % divisor == 0","entry_point":"is_divisible","test":"def check(candidate):\n assert candidate(6, 3) == True\n"}
{"task_id":"task/149","prompt":"from datetime import datetime\n\ndef is_weekday(d = datetime.today()):","canonical_solution":" return d.weekday() <= 4","entry_point":"is_weekday","test":"def check(candidate):\n from datetime import date\n \n assert candidate(date(2020, 10, 25)) == False\n assert candidate(date(2020, 10, 28)) == True\n"}
{"task_id":"task/150","prompt":"def fahrenheit_to_celsius(degrees):","canonical_solution":" return ((degrees - 32) * 5/9)","entry_point":"fahrenheit_to_celsius","test":"def check(candidate):\n assert candidate(77) == 25.0\n"}
{"task_id":"task/151","prompt":"def sum_by(lst, fn):","canonical_solution":" return sum(map(fn, lst))","entry_point":"sum_by","test":"def check(candidate):\n assert candidate([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda v : v['n']) == 20\n"}
{"task_id":"task/152","prompt":"def find_key(dict, val):","canonical_solution":" return next(key for key, value in dict.items() if value == val)","entry_point":"find_key","test":"def check(candidate):\n ages = {\n 'Peter': 10,\n 'Isabel': 11,\n 'Anna': 9,\n }\n assert candidate(ages, 11) == 'Isabel'\n"}
{"task_id":"task/153","prompt":"def to_hex(dec):","canonical_solution":" return hex(dec)","entry_point":"to_hex","test":"def check(candidate):\n assert candidate(41) == 0x29\n assert candidate(332) == 0x14c\n"}
{"task_id":"task/154","prompt":"def clamp_number(num, a, b):","canonical_solution":" return max(min(num, max(a, b)), min(a, b))","entry_point":"clamp_number","test":"def check(candidate):\n assert candidate(2, 3, 5) == 3\n assert candidate(1, -1, -5) == -1\n"}
{"task_id":"task/155","prompt":"from functools import reduce\n\ndef compose_right(*fns):","canonical_solution":" return reduce(lambda f, g: lambda *args: g(f(*args)), fns)","entry_point":"compose_right","test":"def check(candidate):\n add = lambda x, y: x + y\n square = lambda x: x * x\n add_and_square = compose_right(add, square)\n assert add_and_square(1, 2) == 9\n"}
{"task_id":"task/156","prompt":"def days_diff(start, end):","canonical_solution":" return (end - start).days","entry_point":"days_diff","test":"def check(candidate):\n from datetime import date\n \n assert candidate(date(2020, 10, 25), date(2020, 10, 28)) == 3\n"}
{"task_id":"task/157","prompt":"def is_contained_in(a, b):","canonical_solution":" for v in set(a):\n if a.count(v) > b.count(v):\n return False\n return True","entry_point":"is_contained_in","test":"def check(candidate):\n assert candidate([1, 4], [2, 4, 1]) == True\n"}
{"task_id":"task/158","prompt":"def drop_right(a, n = 1):","canonical_solution":" return a[:-n]","entry_point":"drop_right","test":"def check(candidate):\n assert candidate([1, 2, 3]) == [1, 2]\n assert candidate([1, 2, 3], 2) == [1]\n assert candidate([1, 2, 3], 42) == []\n"}
{"task_id":"task/159","prompt":"from functools import reduce\nfrom math import gcd as _gcd\n\ndef gcd(numbers):","canonical_solution":" return reduce(_gcd, numbers)","entry_point":"gcd","test":"def check(candidate):\n assert candidate([8, 36, 28]) == 4\n"}