file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f9597.py
|
def f(value, values):
return value % max(values)
assert f(2, range(4)) == 2
|
benchmark_functions_edited/f1990.py
|
def f(vector1, vector2):
return sum((a*b) for a, b in zip(vector1, vector2))
assert f((3, 1, -1), tuple()) == 0
|
benchmark_functions_edited/f10624.py
|
def f(value):
unique = set()
for c in str(value):
unique.add(c)
return len(unique)
assert f('123') == 3
|
benchmark_functions_edited/f13154.py
|
def f(str1, str2):
if len(str1) != len(str2):
raise ValueError('Strings not same length.')
return sum(s1 != s2 for s1, s2 in zip(str1, str2))
assert f('A', 'T') == 1
|
benchmark_functions_edited/f7448.py
|
def f(value):
return None if value is None else float(value)
assert f('0') == 0
|
benchmark_functions_edited/f8373.py
|
def f(x):
return x ** (1 / 2)
assert f(4) == 2
|
benchmark_functions_edited/f3824.py
|
def f(f, x, h = .001):
return (f(x + h) - 2 * f(x) + f(x - h))/h**2
assert f(lambda x: x, 0) == 0
|
benchmark_functions_edited/f6691.py
|
def f(a):
prev = 1
prevprev = 1
while a > 0:
tmp = prev + prevprev
prevprev = prev
prev = tmp
a -= 1
return prev
assert f(0) == 1
|
benchmark_functions_edited/f4761.py
|
def f(widget):
if hasattr(widget, "get_scale_factor"):
return widget.f()
else:
return 1
assert f(True) == 1
|
benchmark_functions_edited/f5486.py
|
def f(a: int, b: int):
while b > 0:
a, b = b, a % b
return a
assert f(1, 2) == 1
|
benchmark_functions_edited/f13121.py
|
def f(obj_list, feat):
sum = 0
for obj in obj_list:
sum += eval('obj.'+feat)
return sum
assert f([], 'y') == 0
|
benchmark_functions_edited/f12198.py
|
def f(task):
answer = None
level = 0
i = 0
for char in task:
i += 1
if char == "(":
level += 1
elif char == ")":
level -= 1
if level == -1:
answer = i
break
return answer
assert f(r"())") == 3
|
benchmark_functions_edited/f1103.py
|
def f(backdrop, source):
return backdrop + source - (backdrop * source)
assert f(1, 1) == 1
|
benchmark_functions_edited/f13900.py
|
def f(A):
middle = list()
for i in range(len(A)):
possible = 1
for j in range(len(A[i])):
possible *= A[i][j]
middle.append(possible)
record_pct = 0
for i in range(len(middle)):
record_pct += middle[i]
return record_pct
assert f([[1, 0]]) == 0
|
benchmark_functions_edited/f6490.py
|
def f(text):
return int(text.split(' ')[-1][:4] == 'http')
assert f(
'https://github.com/google/eng-edu is not a link with extra text, '
'because there is not a space before the link') == 0
|
benchmark_functions_edited/f4592.py
|
def f(number: int) -> int:
num_zeros = 0
while number:
num_zeros += number // 5
number //= 5
return num_zeros
assert f(21) == 4
|
benchmark_functions_edited/f6982.py
|
def f(nums):
i = 0 # current check point
for val in nums:
if val != nums[i]:
i += 1
nums[i] = val
return i + 1
assert f([1, 1, 2]) == 2
|
benchmark_functions_edited/f5898.py
|
def f(iterable, where, equals):
for item in iterable:
if getattr(item, where, None) == equals:
return item
assert f(range(100), 'imag', 0) == 0
|
benchmark_functions_edited/f3903.py
|
def f(n):
if n <= 2:
return 1
else:
return f(n - 1) + f(n - 2)
assert f(0) == 1
|
benchmark_functions_edited/f8914.py
|
def f(string: str) -> int:
summation = 0
for i, char in enumerate(string):
if i + 1 == len(string):
i = -1
if char == string[i + 1]:
summation += int(char)
return summation
assert f(
"1122"
) == 3
|
benchmark_functions_edited/f8190.py
|
def f(chars):
count = 0
for c in chars[::-1]:
if c != '#':
break
count += 1
return count
assert f('#a#b#c###') == 3
|
benchmark_functions_edited/f6977.py
|
def f(l, depth=1, reps=1):
if depth == 0:
return(None)
elif depth == 1:
return(l)
else:
return([f(l, depth-1, reps)] * reps)
assert f(4) == 4
|
benchmark_functions_edited/f3816.py
|
def f(pred, seq):
for item in seq:
if pred(item):
return item
assert f(lambda n: n == 2, [3, 1, 4, 1, 5, 9, 2, 6, 5]) == 2
|
benchmark_functions_edited/f3645.py
|
def f( p ):
sum = 0
for byte in p[2:]:
sum = 0xff & (sum + byte)
notSum = 0xff & (~sum)
return notSum
assert f(b'\x55\x55\x55\x55\x55') == 0
|
benchmark_functions_edited/f9884.py
|
def f(ar, n):
if n == 0:
return 1
if ar[n] is not None:
return ar[n]
else:
print("call---" + str(n))
ar[n] = n * f(ar, n - 1)
return ar[n]
assert f(None, 0) == 1
|
benchmark_functions_edited/f11864.py
|
def f(expr, val):
if val == 1:
return expr
if val == -1:
return -expr
if val == 0:
return 0
return val * expr
assert f(3, 0) == 0
|
benchmark_functions_edited/f4530.py
|
def f(f, x, p):
result = 0
for a in f:
result *= x
result += a
result %= p
return result
assert f((1,2), 2, 3) == 1
|
benchmark_functions_edited/f2989.py
|
def f(c, h):
return (c - 331.4 - 0.0124 * h) / 0.6
assert f(331.4, 0) == 0
|
benchmark_functions_edited/f13981.py
|
def f(base_number, base_string):
number = 0
for digit in str(base_number):
number = number * len(base_string) + base_string.index(digit)
return number
assert f(4, '0123456789') == 4
|
benchmark_functions_edited/f6877.py
|
def f(n: int) -> int:
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
return n
assert f(10) == 5
|
benchmark_functions_edited/f4231.py
|
def f(team_num):
if team_num == 2:
return 3
if team_num == 3:
return 2
return team_num
assert f(4) == 4
|
benchmark_functions_edited/f9249.py
|
def f(v):
MAX_SIZE = 4
MAX_VERSION_SIZE_2_POW = 5
v = v.split('.')
res = 0
for (ind, val) in enumerate(v):
res += int(val) << ((MAX_SIZE - ind) * MAX_VERSION_SIZE_2_POW)
return res
assert f('0.0.0.0') == 0
|
benchmark_functions_edited/f7892.py
|
def f(x,y):
if x<y:
return -1
elif x==y:
return 0
return 1
assert f(1.3,1.3) == 0
|
benchmark_functions_edited/f8875.py
|
def f(J,M):
mult=0
if abs(M)<=J:
#check if both are half integers or integers
if (2*J)%2==(2*M)%2:
mult=1
return mult
assert f(0, -1) == 0
|
benchmark_functions_edited/f10765.py
|
def f(sequence):
return (sequence[0] + sequence[-1]) * (len(sequence) + 1) / 2 - sum(sequence)
assert f([1, 2, 3, 5, 6]) == 4
|
benchmark_functions_edited/f2881.py
|
def f(n: int) -> int:
return ((n ^ (n - 1)) + 1) >> 1
assert f(0) == 0
|
benchmark_functions_edited/f12095.py
|
def f(a_1, d, n):
a_n = a_1 + d*(n - 1)
return n*(a_1 + a_n) // 2
assert f(1, 2, 3) == 9
|
benchmark_functions_edited/f8775.py
|
def f(i, n):
mask = 2**(n-1)
count = 1
for k in range(n):
if (mask & i) == 0:
count += 1
mask >>= 1
else:
break
return min(count, n)
assert f(19, 4) == 3
|
benchmark_functions_edited/f2593.py
|
def f(word, doc_bow):
return doc_bow.get(word, 0)
assert f(2, {}) == 0
|
benchmark_functions_edited/f5691.py
|
def f(weekday):
return (weekday + 1) % 7
assert f(1) == 2
|
benchmark_functions_edited/f946.py
|
def f(a, b, c):
return a * b * c
assert f(2, 2, 2) == 8
|
benchmark_functions_edited/f3934.py
|
def f(f):
if round(f + 1) - round(f) != 1:
return f + abs(f) / f * 0.5
return round(f)
assert f(-0.499999999) == 0
|
benchmark_functions_edited/f5556.py
|
def f(value):
if value < 1:
value *= -1
length = 0
while value:
value >>= 1
length += 1
return length
assert f(3) == 2
|
benchmark_functions_edited/f3484.py
|
def f(feasible_ind, original_ind):
return sum((f - o)**2 for f, o in zip(feasible_ind, original_ind))
assert f([2,2,2,2,2,2,2,2,2,2], [2,2,2,2,2,2,2,2,2,2]) == 0
|
benchmark_functions_edited/f12938.py
|
def f(M):
B = 3.0 * M / 2.0
A = (B + (1.0 + B ** 2) ** 0.5) ** (2.0 / 3.0)
D = 2 * A * B / (1 + A + A ** 2)
return D
assert f(0) == 0
|
benchmark_functions_edited/f13902.py
|
def f(demand1, demand2):
i, j = demand1
k, l = demand2
if j == k:
return l
elif j < k:
return j
elif i < k:
return i
elif i == k:
return j
assert f( (0, 2), (0, 2) ) == 2
|
benchmark_functions_edited/f8786.py
|
def f(value):
# Try conversion
try:
result = int(value)
except:
result = None
# Return
return result
assert f('1') == 1
|
benchmark_functions_edited/f11072.py
|
def f(snapshot_years, snapshot_idx):
return snapshot_years[snapshot_idx] - snapshot_years[0]
assert f(
[0, 1, 2, 3, 4],
1) == 1
|
benchmark_functions_edited/f10878.py
|
def f(x):
x = abs(x)
return int(round(x ** (1. / 3)))
assert f(10) == 2
|
benchmark_functions_edited/f7860.py
|
def f(value):
value_c = (value-32)*(5/9)
if(hasattr(value_c, 'units')):
value_c.attrs.update(units='degC')
return(value_c)
assert f(32) == 0
|
benchmark_functions_edited/f13781.py
|
def f(contracts_list, param_name):
msg = "Argument `*[argument_name]*` is not valid"
return sum(
[
1 if item["msg"] == msg.replace("*[argument_name]*", param_name) else 0
for item in contracts_list
]
)
assert f(
[
{
"msg": "Argument `*[argument_name]*` is not valid",
"type": "simple",
"subtype": None,
"argument": "value",
}
],
"argument",
) == 0
|
benchmark_functions_edited/f12217.py
|
def f(risk):
_index = 0
if risk == 1.0:
_index = 1
elif risk > 1.0 and risk <= 1.2:
_index = 2
elif risk > 1.2:
_index = 3
return _index
assert f(1.4) == 3
|
benchmark_functions_edited/f1416.py
|
def f(datestring):
return int(datestring[:2])
assert f("01/2012") == 1
|
benchmark_functions_edited/f11549.py
|
def f(delay):
try:
delay = float(delay)
except ValueError:
raise ValueError("{} is not a valid delay (not a number)".format(delay))
if delay < 0:
raise ValueError("{} is not a valid delay (not positive)".format(delay))
return delay
assert f(1) == 1
|
benchmark_functions_edited/f3937.py
|
def f(text, default=0):
try:
return int(text)
except ValueError:
return default
assert f(3) == 3
|
benchmark_functions_edited/f3218.py
|
def f(first_leg, last_leg):
for leg in last_leg:
if leg not in first_leg:
return leg
assert f(set([1, 2, 3, 4]), set([5, 4, 3])) == 5
|
benchmark_functions_edited/f13361.py
|
def f(x, thresold):
result = None
if x > thresold:
result = 1
else:
result = 0
return result
assert f(0.9, 0.6) == 1
|
benchmark_functions_edited/f8807.py
|
def f(data) -> float:
total = 0
day = len(data)
for index, body_fat in enumerate(data):
total += body_fat[3]
return total / day
assert f(
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0
|
benchmark_functions_edited/f2642.py
|
def f(value):
return int.from_bytes(bytearray(value), 'little')
assert f(bytearray([0])) == 0
|
benchmark_functions_edited/f9160.py
|
def f(current, next):
if next > current:
return -1
elif next == current:
return 0
else:
return 1
assert f(1, 0) == 1
|
benchmark_functions_edited/f7791.py
|
def f(value, default=0):
ret_val = default
try:
ret_val = float(value)
except (TypeError, ValueError):
pass
return ret_val
assert f(None, 5) == 5
|
benchmark_functions_edited/f5718.py
|
def f(v, rho):
return .5 * rho * v ** 3
assert f(2, 2) == 8
|
benchmark_functions_edited/f4902.py
|
def f(array):
total_circles = 0
for row in range(len(array)):
total_circles += len(array[row])
return total_circles
assert f(
[
['x', 'x', 'x'],
['x', 'x', 'x'],
['x', 'x', 'x']
]
) == 9
|
benchmark_functions_edited/f10319.py
|
def f(a: int, b: int, p: int) -> int:
result = 1
while b > 0:
if b & 1:
result = (result * a) % p
a = (a * a) % p
b >>= 1
return result
assert f(3, 2, 10) == 9
|
benchmark_functions_edited/f2269.py
|
def f(manifest):
return manifest["manifest"]["schemaVersion"]
assert f({
"manifest": {
"schemaVersion": 1
}
}) == 1
|
benchmark_functions_edited/f5745.py
|
def f(value):
try:
return int(value)
except ValueError:
return None
assert f('1') == 1
|
benchmark_functions_edited/f14226.py
|
def f(s):
if isinstance(s, str):
return len(s.encode())
elif isinstance(s, bytes):
return len(s)
else:
raise TypeError('Cannot determine byte length for type {}'.format(type(s)))
assert f(u'hello') == 5
|
benchmark_functions_edited/f10779.py
|
def f(path):
import os
total_size = 0
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
assert f(
"path/to/test_get_directory_size/empty_dir/empty_subdir") == 0
|
benchmark_functions_edited/f1550.py
|
def f(self):
# return self._hdt.nb_predicates
return 0
assert f('http://www.wikidata.org/prop/statement/P361') == 0
|
benchmark_functions_edited/f7703.py
|
def f(tree, parent):
if type(tree) == str:
return parent
else:
count = 0
for i, child in enumerate(reversed(tree)):
count += f(child, parent + i)
return count
assert f([], 0) == 0
|
benchmark_functions_edited/f12082.py
|
def f(li, index):
#ex :[[0,9,8],[1,2,3],[3,4,5]] the min at index 1 is 2
if (len(li)>0):
return min([e[index] for e in li])
return 0
assert f( [[0, 9]], 0 ) == 0
|
benchmark_functions_edited/f4911.py
|
def f(parameter):
try:
var = int(parameter)
result = var * var
except ValueError:
result = 'Nan'
return result
assert f(2) == 4
|
benchmark_functions_edited/f2528.py
|
def f(i, offset, value):
return i | (value << offset)
assert f(8, 3, 1) == 8
|
benchmark_functions_edited/f401.py
|
def f(v):
try:
v = int(v)
except:
v = 0
return v
assert f("2.2") == 0
|
benchmark_functions_edited/f4841.py
|
def f(x, y):
try:
return int(y)
except ValueError:
return x[y]
assert f({"A": 1, "B": 100}, "A") == 1
|
benchmark_functions_edited/f3463.py
|
def f(data):
n = len(data)
if n < 1:
raise ValueError('len < 1')
return sum(data) / float(n)
assert f([1,3,5]) == 3
|
benchmark_functions_edited/f1867.py
|
def f(n):
c = 0
while n>0:
c += (n & 1)
n >>= 1
return c
assert f(28) == 3
|
benchmark_functions_edited/f10798.py
|
def f(arr):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if mid == len(arr) - 1 or arr[mid] > arr[mid + 1]:
high = mid - 1
else:
low = mid + 1
return low
assert f([1, 2, 3, 4, 3, 2, 1]) == 3
|
benchmark_functions_edited/f10723.py
|
def f(myList):
for elem in myList:
if type(elem) is list:
return 1
else:
return 0
assert f( [[1, [2, [3, [4]]]]]) == 1
|
benchmark_functions_edited/f10610.py
|
def f(n, source, target, helper):
count = 0
if n >= 1:
first = f(n - 1, source, helper, target)
target.append(source.pop())
count += 1
second = f(n - 1, helper, target, source)
count += first + second
return count
assert f(1, [1], [1], [1]) == 1
|
benchmark_functions_edited/f2579.py
|
def f(seq):
nCount = seq.count('N')
if( nCount > 0 ):
return nCount
else:
return 0
assert f("AAACCCGGTTT") == 0
|
benchmark_functions_edited/f664.py
|
def f(x, scan, m, q):
return scan - x * m - q
assert f(1, 10, 2, 3) == 5
|
benchmark_functions_edited/f13233.py
|
def f(deps1, deps2):
matches = 0
for dep1 in deps1:
for dep2 in deps2:
if dep1.is_equivalent(dep2):
matches += 1
break
return matches
assert f(set(), set()) == 0
|
benchmark_functions_edited/f11230.py
|
def f(dims: tuple):
number: int = 1
def multipy(dim: int):
nonlocal number
number = number * dim
for dim in dims:
multipy(dim)
return int(number)
assert f((2,)) == 2
|
benchmark_functions_edited/f9487.py
|
def f(v):
s = bin(v)[2:]
r = s.find("0")
l = len(s) - r
if (r == -1) or ((l - 1) < 0):
return None
return 1 << (l - 1)
assert f(13) == 2
|
benchmark_functions_edited/f6215.py
|
def f(x, w=16):
if x == 0:
return w
t = 1
r = 0
while x & t == 0:
t <<= 1
r += 1
return r
assert f(9) == 0
|
benchmark_functions_edited/f5051.py
|
def f( var1, var2):
total = 0
if var1 != "NaN" and var2 != "NaN":
total = var1 + var2
return total
assert f(5, 3) == 8
|
benchmark_functions_edited/f8489.py
|
def f(text):
return len(text) - len(text.lstrip())
assert f(r'a') == 0
|
benchmark_functions_edited/f3489.py
|
def f(num, total): # type: (int, int) -> float
perc = num * 100 / total if total is not 0 else 0
return float(round(perc, 2))
assert f(0, 10) == 0
|
benchmark_functions_edited/f7819.py
|
def f(morning_cars,requested,returned,max_cars):
return min(max(morning_cars - requested,0) + returned, max_cars)
assert f(4,2,0,2) == 2
|
benchmark_functions_edited/f12929.py
|
def f(value, default=0):
try:
return int(value)
except ValueError:
return default
assert f("abc", 3) == 3
|
benchmark_functions_edited/f4281.py
|
def f(sentence):
if "!" in sentence:
return 1
else:
return 0
assert f(
"This is a test sentence!!!") == 1
|
benchmark_functions_edited/f9725.py
|
def f(n):
a, b = 0, 1 #Note multiple assignment!
counter = 1
while counter < n:
print (a, end=' ')
a, b = b, a+b
counter += 1
print(a)
print(__name__)
return(0)
assert f(30) == 0
|
benchmark_functions_edited/f14371.py
|
def f(x,p):
i = 1
if p == 0:
return 1
res = x
while i < p:
res *= x
i += 1
return res
assert f(3,0) == 1
|
benchmark_functions_edited/f10597.py
|
def f(col):
col_num = {
'a': 1,
'b': 2,
'c': 3
}
return col_num[col]
assert f('a') == 1
|
benchmark_functions_edited/f2500.py
|
def f(tlvs, cls):
for tlv in tlvs:
if isinstance(tlv, cls):
return tlv
assert f([1, 'a'], int) == 1
|
benchmark_functions_edited/f10171.py
|
def f(bib):
cpt = 0
for entry in bib:
if "code" in entry:
if entry["code"][:2] != "No":
cpt += 1
print(str(cpt) + " articles provide their source code.")
return cpt
assert f(
[
{
"key": "test-key",
"title": "Test title",
"code": "https://github.com/jads-nl/intro-to-python/blob/master/02_functions/exercises/test.py",
},
{
"key": "test-key-2",
"title": "Test title 2",
"code": "No code",
},
]
) == 1
|
benchmark_functions_edited/f10012.py
|
def f(y):
x = y >> 21
return x if x <= 1024 else - (2048 - x)
assert f(0) == 0
|
benchmark_functions_edited/f12617.py
|
def f(x):
x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF
x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF
x = ((x >> 16) ^ x) & 0xFFFFFFFF
return x
assert f(0) == 0
|
benchmark_functions_edited/f546.py
|
def f(x):
return x.real if isinstance(x, complex) else x
assert f(3 + 4j) == 3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.