common_id
stringlengths 5
5
| image
stringlengths 18
18
| code
stringlengths 55
1.44k
|
---|---|---|
11271 | Test/png/11271.png | # Write a function to extract values between quotation marks of a string.
import re
def extract_values(text):
return re.findall(r'"(.*?)"', text)
|
10414 | Test/png/10414.png | def do_help(self, arg):
print(self.response_prompt, file=self.stdout)
return cmd.Cmd.do_help(self, arg)
|
10459 | Test/png/10459.png | def write(self, bytes_):
string = bytes_.decode(self._encoding)
self._file.write(string)
|
10497 | Test/png/10497.png | def replace(self, **k):
if self.date != 'infinity':
return Date(self.date.replace(**k))
else:
return Date('infinity')
|
10582 | Test/png/10582.png | def add_example(self, example):
"Add an example to the list of examples, checking it first."
self.check_example(example)
self.examples.append(example)
|
10335 | Test/png/10335.png | def write(self, path):
with open(path, "wb") as fout:
fout.write(self.m_buf)
|
10737 | Test/png/10737.png | # Write a python function to find the element occurring odd number of times.
def get_Odd_Occurrence(arr, arr_size):
for i in range(0, arr_size):
count = 0
for j in range(0, arr_size):
if arr[i] == arr[j]:
count += 1
if count % 2 != 0:
return arr[i]
return -1
|
10531 | Test/png/10531.png | def validate(cls, policy):
return policy in [cls.OPEN, cls.APPROVAL, cls.CLOSED]
|
10455 | Test/png/10455.png | def warning(msg):
_flush()
sys.stderr.write("\033[1;7;33;40mWARNING: {}\033[0m\n".format(msg))
sys.stderr.flush()
|
10603 | Test/png/10603.png | def index_row(self, dataframe):
return dataframe.loc[self.kwargs[self.lookup_url_kwarg]].to_frame().T
|
10326 | Test/png/10326.png | def simpixel(new=0, autoraise=True):
simpixel_driver.open_browser(new=new, autoraise=autoraise)
|
10569 | Test/png/10569.png | def body(self):
if not hasattr(self, '_body'):
self._body = inspect.getsource(self.module)
return self._body
|
10621 | Test/png/10621.png | def iteritems(data, **kwargs):
return iter(data.items(**kwargs)) if IS_PY3 else data.iteritems(**kwargs)
|
10879 | Test/png/10879.png | # Write a function to find the perimeter of a pentagon.
import math
def perimeter_pentagon(a):
perimeter = 5 * a
return perimeter
|
10940 | Test/png/10940.png | # Write a function to get the n largest items from a dataset.
import heapq
def larg_nnum(list1, n):
largest = heapq.nlargest(n, list1)
return largest
|
10486 | Test/png/10486.png | def namelist(self):
names = []
for member in self.filelist:
names.append(member.filename)
return names
|
11239 | Test/png/11239.png | # Write a function to find minimum number of coins that make a given value.
import sys
def min_coins(coins, m, V):
if V == 0:
return 0
res = sys.maxsize
for i in range(0, m):
if coins[i] <= V:
sub_res = min_coins(coins, m, V - coins[i])
if sub_res != sys.maxsize and sub_res + 1 < res:
res = sub_res + 1
return res
|
10893 | Test/png/10893.png | # Write a function to find the focus of a parabola.
def parabola_focus(a, b, c):
focus = ((-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a)))
return focus
|
10814 | Test/png/10814.png | # Write a function to add the given list to the given tuples.
def add_lists(test_list, test_tup):
res = tuple(list(test_tup) + test_list)
return res
|
11011 | Test/png/11011.png | # Write a python function to check whether the count of inversion of two types are same or not.
import sys
def solve(a, n):
mx = -sys.maxsize - 1
for j in range(1, n):
if mx > a[j]:
return False
mx = max(mx, a[j - 1])
return True
|
10611 | Test/png/10611.png | def spec_formatter(cls, spec):
" Formats the elements of an argument set appropriately"
return type(spec)((k, str(v)) for (k, v) in spec.items())
|
11120 | Test/png/11120.png | # Write a python function to remove odd numbers from a given list.
def remove_odd(l):
for i in l:
if i % 2 != 0:
l.remove(i)
return l
|
10444 | Test/png/10444.png | def node_heap(self):
log.info('Heap')
res = self.__exchange('print(node.heap())')
log.info(res)
return int(res.split('\r\n')[1])
|
10428 | Test/png/10428.png | def complement(clr):
clr = color(clr)
colors = colorlist(clr)
colors.append(clr.complement)
return colors
|
11203 | Test/png/11203.png | # Write a function to remove lowercase substrings from a given string by using regex.
import re
def remove_lowercase(str1):
remove_lower = lambda text: re.sub("[a-z]", "", text)
result = remove_lower(str1)
return result
|
10735 | Test/png/10735.png | # Write a python function to remove all digits from a list of strings.
import re
def remove(list):
pattern = "[0-9]"
list = [re.sub(pattern, "", i) for i in list]
return list
|
10780 | Test/png/10780.png | # Write a python function to check whether the given number can be represented as difference of two squares or not.
def dif_Square(n):
if n % 4 != 2:
return True
return False
|
10252 | Test/png/10252.png | def build(self, **kwargs):
self.yacc = yacc.yacc(module=self, **kwargs)
|
11281 | Test/png/11281.png | # Write a python function to calculate the product of the unique numbers of a given list.
def unique_product(list_data):
temp = list(set(list_data))
p = 1
for i in temp:
p *= i
return p
|
10332 | Test/png/10332.png | def unlock(self, pwd):
if self.store.is_encrypted():
return self.store.unlock(pwd)
|
11209 | Test/png/11209.png | # Write a python function to find common divisor between two numbers in a given pair.
def ngcd(x, y):
i = 1
while i <= x and i <= y:
if x % i == 0 and y % i == 0:
gcd = i
i += 1
return gcd
def num_comm_div(x, y):
n = ngcd(x, y)
result = 0
z = int(n**0.5)
i = 1
while i <= z:
if n % i == 0:
result += 2
if i == n / i:
result -= 1
i += 1
return result
|
10187 | Test/png/10187.png | def addInstance(self, groundTruth, prediction, record=None, result=None):
self.value = self.avg(prediction)
|
10643 | Test/png/10643.png | def set_power(self, value=False):
power = (yield from self.handle_set(
self.API.get('power'), int(value)))
return bool(power)
|
10847 | Test/png/10847.png | # Write a function to find the circumference of a circle.
def circle_circumference(r):
perimeter = 2 * 3.1415 * r
return perimeter
|
10626 | Test/png/10626.png | def save(self, ds_name, data, dtype=None):
return self.create_dataset(ds_name, data, dtype)
|
10365 | Test/png/10365.png | def absolute_signal_to_noise_map(self):
return np.divide(np.abs(self.image), self.noise_map)
|
10703 | Test/png/10703.png | def open(name=None, fileobj=None, closefd=True):
return Guesser().open(name=name, fileobj=fileobj, closefd=closefd)
|
11002 | Test/png/11002.png | # Write a function to find the maximum value in a given heterogeneous list.
def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return max_val
|
10630 | Test/png/10630.png | def dictify(a_named_tuple):
return dict((s, getattr(a_named_tuple, s)) for s in a_named_tuple._fields)
|
10538 | Test/png/10538.png | def delete(self):
url = PATHS['DELETE'] % self.id
return self.api.post(url=url)
|
10485 | Test/png/10485.png | def _process_current(self, handle, op, dest_path=None, dest_name=None):
unrarlib.RARProcessFileW(handle, op, dest_path, dest_name)
|
10951 | Test/png/10951.png | # Write a function to sort the given list based on the occurrence of first element of tuples.
def sort_on_occurence(lst):
dct = {}
for i, j in lst:
dct.setdefault(i, []).append(j)
return [(i, *dict.fromkeys(j), len(j)) for i, j in dct.items()]
|
10395 | Test/png/10395.png | def has_edit_permission(self, request):
return request.user.is_authenticated and request.user.is_active and request.user.is_staff
|
10276 | Test/png/10276.png | def get_cache_access_details(key=None):
from cloudaux.gcp.decorators import _GCP_CACHE
return _GCP_CACHE.get_access_details(key=key)
|
10645 | Test/png/10645.png | def set_mute(self, value=False):
mute = (yield from self.handle_set(self.API.get('mute'), int(value)))
return bool(mute)
|
10280 | Test/png/10280.png | def _cell(x):
x_no_none = [i if i is not None else "" for i in x]
return array(x_no_none, dtype=np_object)
|
11218 | Test/png/11218.png | # Write a function to find the number of subsequences having product smaller than k for the given non negative array.
def no_of_subsequences(arr, k):
n = len(arr)
dp = [[0 for i in range(n + 1)] for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = dp[i][j - 1]
if arr[j - 1] <= i and arr[j - 1] > 0:
dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
return dp[k][n]
|
10229 | Test/png/10229.png | def sys_rt_sigprocmask(self, cpu, how, newset, oldset):
return self.sys_sigprocmask(cpu, how, newset, oldset)
|
10920 | Test/png/10920.png | # Write a python function to find the sum of fourth power of n natural numbers.
import math
def fourth_Power_Sum(n):
sum = 0
for i in range(1, n + 1):
sum = sum + (i * i * i * i)
return sum
|
11267 | Test/png/11267.png | # Write a function to find the largest sum of contiguous subarray in the given array.
def max_sub_array_sum(a, size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_ending_here < 0:
max_ending_here = 0
elif max_so_far < max_ending_here:
max_so_far = max_ending_here
return max_so_far
|
11122 | Test/png/11122.png | # Write a python function to check whether the value exists in a sequence or not.
def overlapping(list1, list2):
c = 0
d = 0
for i in list1:
c += 1
for i in list2:
d += 1
for i in range(0, c):
for j in range(0, d):
if list1[i] == list2[j]:
return 1
return 0
|
10532 | Test/png/10532.png | def validate(cls, policy):
return policy in [cls.PUBLIC, cls.MEMBERS, cls.ADMINS]
|
10612 | Test/png/10612.png | def dispatch(self, func):
self.callees.append(self._make_dispatch(func))
return self._make_wrapper(func)
|
10394 | Test/png/10394.png | def remove_entity(self, name):
self.entities.remove(name)
self.padaos.remove_entity(name)
|
11200 | Test/png/11200.png | # Write a function to search an element in the given array by using binary search.
def binary_search(item_list, item):
first = 0
last = len(item_list) - 1
found = False
while first <= last and not found:
mid = (first + last) // 2
if item_list[mid] == item:
found = True
else:
if item < item_list[mid]:
last = mid - 1
else:
first = mid + 1
return found
|
10209 | Test/png/10209.png | def getTopologiesForStateLocation(self, name):
return filter(lambda t: t.state_manager_name == name, self.topologies)
|
10248 | Test/png/10248.png | def append(self, linenumber, raw_text, cells):
self.rows.append(Row(linenumber, raw_text, cells))
|
10689 | Test/png/10689.png | def with_revision(self, label, number):
t = self.clone()
t.revision = Revision(label, number)
return t
|
10518 | Test/png/10518.png | def check_max_filesize(chosen_file, max_size):
if os.path.getsize(chosen_file) > max_size:
return False
else:
return True
|
11053 | Test/png/11053.png | # Write a function to find the difference between two consecutive numbers in a given list.
def diff_consecutivenums(nums):
result = [b - a for a, b in zip(nums[:-1], nums[1:])]
return result
|
10402 | Test/png/10402.png | def node_radius(self, node):
return self.get_idx(node) * self.scale + self.internal_radius
|
10266 | Test/png/10266.png | def close(self):
if self._ctx is not None:
ftdi.free(self._ctx)
self._ctx = None
|
10808 | Test/png/10808.png | # Write a function to find the next smallest palindrome of a specified number.
import sys
def next_smallest_palindrome(num):
numstr = str(num)
for i in range(num + 1, sys.maxsize):
if str(i) == str(i)[::-1]:
return i
|
10366 | Test/png/10366.png | def map_function(self, func, *arg_lists):
return GridStack(*[func(*args) for args in zip(self, *arg_lists)])
|
10453 | Test/png/10453.png | def run(self, cmd, *args, **kwargs):
runner = self.ctx.run if self.ctx else None
return run(cmd, runner=runner, *args, **kwargs)
|
10524 | Test/png/10524.png | def node_has_namespace(node: BaseEntity, namespace: str) -> bool:
ns = node.get(NAMESPACE)
return ns is not None and ns == namespace
|
11178 | Test/png/11178.png | # Write a function to find the pairwise addition of the elements of the given tuples.
def add_pairwise(test_tup):
res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
return res
|
10212 | Test/png/10212.png | def copy(self, new_object):
new_object.classdesc = self.classdesc
for name in self.classdesc.fields_names:
new_object.__setattr__(name, getattr(self, name))
|
10790 | Test/png/10790.png | # Write a function to find the volume of a sphere.
import math
def volume_sphere(r):
volume = (4 / 3) * math.pi * r * r * r
return volume
|
10315 | Test/png/10315.png | def drawCircle(self, x0, y0, r, color=None):
md.draw_circle(self.set, x0, y0, r, color)
|
10188 | Test/png/10188.png | def _setPath(cls):
cls._path = os.path.join(os.environ['NTA_DYNAMIC_CONF_DIR'],
cls.customFileName)
|
11096 | Test/png/11096.png | # Write a python function to find the highest power of 2 that is less than or equal to n.
def highest_Power_of_2(n):
res = 0
for i in range(n, 0, -1):
if (i & (i - 1)) == 0:
res = i
break
return res
|
10989 | Test/png/10989.png | # Write a python function to check if the elements of a given list are unique or not.
def all_unique(test_list):
if len(test_list) > len(set(test_list)):
return False
return True
|
10249 | Test/png/10249.png | def dump(self):
for table in self.tables:
print("*** %s ***" % table.name)
table.dump()
|
10181 | Test/png/10181.png | def getVersion():
with open(os.path.join(REPO_DIR, "VERSION"), "r") as versionFile:
return versionFile.read().strip()
|
10130 | Test/png/10130.png | def _num_cpus_darwin():
p = subprocess.Popen(['sysctl', '-n', 'hw.ncpu'], stdout=subprocess.PIPE)
return p.stdout.read()
|
10171 | Test/png/10171.png | def sf01(arr):
s = arr.shape
return arr.swapaxes(0, 1).reshape(s[0] * s[1], *s[2:])
|
10851 | Test/png/10851.png | # Write a function to find number of lists present in the given tuple.
def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input)
|
10562 | Test/png/10562.png | def substitute(prev, *args, **kw):
template_obj = string.Template(*args, **kw)
for data in prev:
yield template_obj.substitute(data)
|
10172 | Test/png/10172.png | def terminate(self):
if self._pool is not None:
self._pool.terminate()
self._pool.join()
self._pool = None
|
10837 | Test/png/10837.png | # Write a function to calculate magic square.
def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum(lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0, iSize):
result1 += my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize - 1, -1, -1):
result2 += my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list)) > 1:
return False
return True
|
11138 | Test/png/11138.png | # Write a function to find the directrix of a parabola.
def parabola_directrix(a, b, c):
directrix = (int)(c - ((b * b) + 1) * 4 * a)
return directrix
|
11226 | Test/png/11226.png | # Write a function to find the square root of a perfect number.
import math
def sqrt_root(num):
sqrt_root = math.pow(num, 0.5)
return sqrt_root
|
10272 | Test/png/10272.png | def locked_delete(self):
if self._cache:
self._cache.delete(self._key_name)
self._delete_entity()
|
10157 | Test/png/10157.png | def depth(n, tree):
d = 0
parent = tree[n]
while parent is not None:
d += 1
parent = tree[parent]
return d
|
11192 | Test/png/11192.png | # Write a function to remove the matching tuples from the given two tuples.
def remove_matching_tuple(test_list1, test_list2):
res = [sub for sub in test_list1 if sub not in test_list2]
return res
|
10690 | Test/png/10690.png | def formatter(color, s):
if no_coloring:
return s
return "{begin}{s}{reset}".format(begin=color, s=s, reset=Colors.RESET)
|
10379 | Test/png/10379.png | def add_program_dir(self, directory):
dirs = list(self.PROGRAM_DIRS)
dirs.append(directory)
self.PROGRAM_DIRS = dirs
|
10734 | Test/png/10734.png | # Write a function to check if the given tuple list has all k elements.
def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return res
|
10436 | Test/png/10436.png | def _censor_with(x, range, value=None):
return [val if range[0] <= val <= range[1] else value
for val in x]
|
10769 | Test/png/10769.png | # Write a python function to count number of substrings with the sum of digits equal to their length.
from collections import defaultdict
def count_Substrings(s, n):
count, sum = 0, 0
mp = defaultdict(lambda: 0)
mp[0] += 1
for i in range(n):
sum += ord(s[i]) - ord("0")
count += mp[sum - (i + 1)]
mp[sum - (i + 1)] += 1
return count
|
10795 | Test/png/10795.png | # Write a function to merge three dictionaries into a single expression.
import collections as ct
def merge_dictionaries_three(dict1, dict2, dict3):
merged_dict = dict(ct.ChainMap({}, dict1, dict2, dict3))
return merged_dict
|
11173 | Test/png/11173.png | # Write a function to drop empty items from a given dictionary.
def drop_empty(dict1):
dict1 = {key: value for (key, value) in dict1.items() if value is not None}
return dict1
|
10350 | Test/png/10350.png | def _get_action_by_name(op, name):
actions = get_actions(op)
for action in actions:
if action.get('name') == name:
return action
|
10197 | Test/png/10197.png | def _dump(self, tag, x, lo, hi):
for i in xrange(lo, hi):
yield '%s %s' % (tag, x[i])
|
10586 | Test/png/10586.png | def prune(self, var, value, removals):
"Rule out var=value."
self.curr_domains[var].remove(value)
if removals is not None:
removals.append((var, value))
|
11021 | Test/png/11021.png | # Write a python function to print positive numbers in a list.
def pos_nos(list1):
for num in list1:
if num >= 0:
return num
|
10195 | Test/png/10195.png | def countOf(a, b):
"Return the number of times b occurs in a."
count = 0
for i in a:
if i == b:
count += 1
return count
|
11087 | Test/png/11087.png | # Write a function to find the surface area of a cuboid.
def surfacearea_cuboid(l, w, h):
SA = 2 * (l * w + l * h + w * h)
return SA
|
10798 | Test/png/10798.png | # Write a python function to find the length of the longest word.
def len_log(list1):
max = len(list1[0])
for i in list1:
if len(i) > max:
max = len(i)
return max
|