common_id
stringlengths
5
5
image
stringlengths
18
18
code
stringlengths
55
1.44k
10670
Test/png/10670.png
def gmv(a, b): return np.exp(np.square(np.log(a) - np.log(b)).mean())
10456
Test/png/10456.png
def error(msg): _flush() sys.stderr.write("\033[1;37;41mERROR: {}\033[0m\n".format(msg)) sys.stderr.flush()
10146
Test/png/10146.png
def _writable_dir(path): return os.path.isdir(path) and os.access(path, os.W_OK)
10778
Test/png/10778.png
# Write a function to find whether all the given tuples have equal length or not. def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return "All tuples have same length" else: return "All tuples do not have same length"
10552
Test/png/10552.png
def mongo(daemon=False, port=20771): cmd = "mongod --port {0}".format(port) if daemon: cmd += " --fork" run(cmd)
10617
Test/png/10617.png
def update(self, id, name): return super(Keys, self).update(id, name=name)
10576
Test/png/10576.png
def is_categorical_type(ary): "Checks whether the array is either integral or boolean." ary = np.asanyarray(ary) return is_integer_type(ary) or ary.dtype.kind == 'b'
10220
Test/png/10220.png
def send(self, str, end='\n'): return self._process.stdin.write(str+end)
10449
Test/png/10449.png
def minus(*args): if len(args) == 1: return -to_numeric(args[0]) return to_numeric(args[0]) - to_numeric(args[1])
10568
Test/png/10568.png
def license_is_oa(license): for oal in OA_LICENSES: if re.search(oal, license): return True return False
10245
Test/png/10245.png
def t_intnumber(self, t): r'-?\d+' t.value = int(t.value) t.type = 'NUMBER' return t
10241
Test/png/10241.png
def forward(self, input): return th.nn.functional.linear(input, self.weight.div(self.weight.pow(2).sum(0).sqrt()))
10355
Test/png/10355.png
def write_config(self): with open(self.config_file, "w") as config_file: self.cfg.write(config_file)
11238
Test/png/11238.png
# Write a function to find the ration of negative numbers in an array of integers. from array import array def negative_count(nums): n = len(nums) n1 = 0 for x in nums: if x < 0: n1 += 1 else: None return round(n1 / n, 2)
10644
Test/png/10644.png
def get_mute(self): mute = (yield from self.handle_int(self.API.get('mute'))) return bool(mute)
10680
Test/png/10680.png
def expandpath(path): return os.path.abspath(os.path.expandvars(os.path.expanduser(path)))
10543
Test/png/10543.png
def j2(x): to_return = 2./(x+1e-15)*j1(x) - j0(x) to_return[x == 0] = 0 return to_return
10429
Test/png/10429.png
def swatch(self, x, y, w=35, h=35, roundness=0): _ctx.fill(self) _ctx.rect(x, y, w, h, roundness)
10602
Test/png/10602.png
def git_tag(tag): print('Tagging "{}"'.format(tag)) msg = '"Released version {}"'.format(tag) Popen(['git', 'tag', '-s', '-m', msg, tag]).wait()
10113
Test/png/10113.png
def beforeContext(self): mods = sys.modules.copy() self._mod_stack.append(mods)
10170
Test/png/10170.png
def copy_obs_dict(obs): return {k: np.copy(v) for k, v in obs.items()}
10625
Test/png/10625.png
def spatial_map(icc, thr, mode='+'): return thr_img(icc_img_to_zscore(icc), thr=thr, mode=mode).get_data()
10800
Test/png/10800.png
# Write a function to check whether the given number is undulating or not. def is_undulating(n): if len(n) <= 2: return False for i in range(2, len(n)): if n[i - 2] != n[i]: return False return True
10619
Test/png/10619.png
def send(self, *args, **kwargs): self.write(*args, **kwargs) self.flush()
10584
Test/png/10584.png
def lcv(var, assignment, csp): "Least-constraining-values heuristic." return sorted(csp.choices(var), key=lambda val: csp.nconflicts(var, val, assignment))
11056
Test/png/11056.png
# Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values. def bin_coff(n, r): val = 1 if r > (n - r): r = n - r for i in range(0, r): val *= n - i val //= i + 1 return val def find_ways(M): n = M // 2 a = bin_coff(2 * n, n) b = a // (n + 1) return b
10203
Test/png/10203.png
def output_eol_literal_marker(self, m): marker = ':' if m.group(1) is None else '' return self.renderer.eol_literal_marker(marker)
11285
Test/png/11285.png
# Write a python function to find the last digit in factorial of a given number. def last_Digit_Factorial(n): if n == 0: return 1 elif n <= 2: return n elif n == 3: return 6 elif n == 4: return 4 else: return 0
10985
Test/png/10985.png
# Write a function to filter a dictionary based on values. def dict_filter(dict, n): result = {key: value for (key, value) in dict.items() if value >= n} return result
10675
Test/png/10675.png
def validate(self): for env in list(self): if not env.exists: self.remove(env)
10742
Test/png/10742.png
# Write a python function to find the missing number in a sorted array. def find_missing(ar, N): l = 0 r = N - 1 while l <= r: mid = (l + r) / 2 mid = int(mid) if ar[mid] != mid + 1 and ar[mid - 1] == mid: return mid + 1 elif ar[mid] != mid + 1: r = mid - 1 else: l = mid + 1 return -1
10116
Test/png/10116.png
def new_qt_console(self, evt=None): return connect_qtconsole(self.ipkernel.connection_file, profile=self.ipkernel.profile)
10165
Test/png/10165.png
def _atexit(self): if self._started: self.stop() if self.auto_data: self.save()
10474
Test/png/10474.png
def apply_filters(self, query, filters): assert isinstance(query, peewee.Query) assert isinstance(filters, dict)
10217
Test/png/10217.png
def make_tarfile(output_filename, source_dir): with tarfile.open(output_filename, "w:gz") as tar: tar.add(source_dir, arcname=os.path.basename(source_dir))
10376
Test/png/10376.png
def start(self): self.music.start() if not self.start_paused: self.rocket.start()
11044
Test/png/11044.png
# Write a function to check whether the given month name contains 28 days or not. def check_monthnum(monthname1): if monthname1 == "February": return True else: return False
10324
Test/png/10324.png
def fillHSV(self, hsv, start=0, end=-1): self.fill(conversions.hsv2rgb(hsv), start, end)
10959
Test/png/10959.png
# Write a function to insert an element before each element of a list. def insert_element(list, element): list = [v for elt in list for v in (element, elt)] return list
11240
Test/png/11240.png
# Write a function to check if the two given strings are permutations of each other. def check_permutation(str1, str2): n1 = len(str1) n2 = len(str2) if n1 != n2: return False a = sorted(str1) str1 = " ".join(a) b = sorted(str2) str2 = " ".join(b) for i in range(0, n1, 1): if str1[i] != str2[i]: return False return True
10117
Test/png/10117.png
def abort(self): assert not self.ready(), "Can't abort, I am already done!" return self._client.abort(self.msg_ids, targets=self._targets, block=True)
10958
Test/png/10958.png
# Write a python function to count the occcurences of an element in a tuple. def count_X(tup, x): count = 0 for ele in tup: if ele == x: count = count + 1 return count
10489
Test/png/10489.png
def contains(self, i): return self.start <= i.start and i.end <= self.end
10722
Test/png/10722.png
# Write a python function to find the volume of a triangular prism. def find_Volume(l, b, h): return (l * b * h) / 2
10628
Test/png/10628.png
def duplicated(values: Sequence): vals = pd.Series(values) return vals[vals.duplicated()]
10903
Test/png/10903.png
# Write a python function to find the first position of an element in a sorted array. def first(arr, x, n): low = 0 high = n - 1 res = -1 while low <= high: mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid high = mid - 1 return res
10963
Test/png/10963.png
# Write a function to choose specified number of colours from three different colours and generate all the combinations with repetitions. from itertools import combinations_with_replacement def combinations_colors(l, n): return list(combinations_with_replacement(l, n))
10613
Test/png/10613.png
def sdcone(x, rho): U, V = np.linalg.eigh(x) return V.dot(np.diag(np.maximum(U, 0)).dot(V.T))
10184
Test/png/10184.png
def getTotalw(self): w = sum([field.w for field in self.fields]) return w
11154
Test/png/11154.png
# Write a python function to count the occurence of all elements of list in a tuple. from collections import Counter def count_Occurrence(tup, lst): count = 0 for item in tup: if item in lst: count += 1 return count
10751
Test/png/10751.png
# Write a function to find sequences of lowercase letters joined with an underscore using regex. import re def text_match(text): patterns = "^[a-z]+_[a-z]+$" if re.search(patterns, text): return "Found a match!" else: return "Not matched!"
10322
Test/png/10322.png
def construct(cls, project, **desc): return cls(project.drivers, maker=project.maker, **desc)
10223
Test/png/10223.png
def emit(self, op_code, *args): self.tape.append(OP_CODES[op_code](*args))
10230
Test/png/10230.png
def sys_mmap_pgoff(self, address, size, prot, flags, fd, offset): return self.sys_mmap2(address, size, prot, flags, fd, offset)
10369
Test/png/10369.png
def volume(self): return (self.x2 - self.x1) * (self.y2 - self.y1) * (self.z2 - self.z1)
10856
Test/png/10856.png
# Write a function to divide a number into two parts such that the sum of digits is maximum. def sum_digits_single(x): ans = 0 while x: ans += x % 10 x //= 10 return ans def closest(x): ans = 0 while ans * 10 + 9 <= x: ans = ans * 10 + 9 return ans def sum_digits_twoparts(N): A = closest(N) return sum_digits_single(A) + sum_digits_single(N - A)
11099
Test/png/11099.png
# Write a function to convert more than one list to nested dictionary. def convert_list_dictionary(l1, l2, l3): result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)] return result
10875
Test/png/10875.png
# Write a python function to find smallest power of 2 greater than or equal to n. def next_Power_Of_2(n): count = 0 if n and not (n & (n - 1)): return n while n != 0: n >>= 1 count += 1 return 1 << count
10389
Test/png/10389.png
def base_boxes(self): return sorted(list(set([name for name, provider in self._box_list()])))
11112
Test/png/11112.png
# Write a python function to find the minimum of two numbers. def minimum(a, b): if a <= b: return a else: return b
10308
Test/png/10308.png
def play_now(self, requester: int, track: dict): self.add_next(requester, track) await self.play(ignore_shuffle=True)
11243
Test/png/11243.png
# Write a function to find the top or bottom surface area of a cylinder. def topbottom_surfacearea(r): toporbottomarea = 3.1415 * r * r return toporbottomarea
10817
Test/png/10817.png
# Write a python function to find the count of rotations of a binary string with odd value. def odd_Equivalent(s, n): count = 0 for i in range(0, n): if s[i] == "1": count = count + 1 return count
10565
Test/png/10565.png
def err(format_msg, *args, **kwargs): exc_info = kwargs.pop("exc_info", False) stderr.warning(str(format_msg).format(*args, **kwargs), exc_info=exc_info)
10909
Test/png/10909.png
# Write a python function to check whether the elements in a list are same or not. def chkList(lst): return len(set(lst)) == 1
10745
Test/png/10745.png
# Write a function to sort a given mixed list of integers and strings. def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
10905
Test/png/10905.png
# Write a function to perform the exponentiation of the given two tuples. def find_exponentio(test_tup1, test_tup2): res = tuple(ele1**ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return res
10201
Test/png/10201.png
def remove(self, value): if value not in self: raise KeyError(value) self.discard(value)
11184
Test/png/11184.png
# Write a python function to find the sum of the largest and smallest value in a given array. def big_sum(nums): sum = max(nums) + min(nums) return sum
10218
Test/png/10218.png
def queries_map(): qs = _all_metric_queries() return dict(zip(qs[0], qs[1]) + zip(qs[2], qs[3]))
10300
Test/png/10300.png
def join(self, room): self.socket.rooms.add(self._get_room_name(room))
10131
Test/png/10131.png
def connect(com, peers, tree, pub_url, root_id): com.connect(peers, tree, pub_url, root_id)
10570
Test/png/10570.png
def _record_sort_by_indicators(record): for tag, fields in record.items(): record[tag] = _fields_sort_by_indicators(fields)
10622
Test/png/10622.png
def iterkeys(data, **kwargs): return iter(data.keys(**kwargs)) if IS_PY3 else data.iterkeys(**kwargs)
10122
Test/png/10122.png
def add_section(self): sect = CodeBuilder(self.indent_amount) self.code.append(sect) return sect
11123
Test/png/11123.png
# Write a python function to find a pair with highest product from a given array of integers. def max_Product(arr): arr_len = len(arr) if arr_len < 2: return "No pairs exists" x = arr[0] y = arr[1] for i in range(0, arr_len): for j in range(i + 1, arr_len): if arr[i] * arr[j] > x * y: x = arr[i] y = arr[j] return x, y
10684
Test/png/10684.png
def show(self): self.parent.addLayout(self._logSelectLayout) self.menuCount += 1 self._connectSlots()
11249
Test/png/11249.png
# Write a function to find if the given number is abundant or not. import math def get_sum(n): sum = 0 i = 1 while i <= (math.sqrt(n)): if n % i == 0: if n / i == i: sum = sum + i else: sum = sum + i sum = sum + (n / i) i = i + 1 sum = sum - n return sum def check_abundant(n): if get_sum(n) > n: return True else: return False
10338
Test/png/10338.png
def info(txt): print("%s# %s%s%s" % (PR_EMPH_CC, get_time_stamp(), txt, PR_NC)) sys.stdout.flush()
11103
Test/png/11103.png
# Write a python function to find the first non-repeated character in a given string. def first_non_repeating_character(str1): char_order = [] ctr = {} for c in str1: if c in ctr: ctr[c] += 1 else: ctr[c] = 1 char_order.append(c) for c in char_order: if ctr[c] == 1: return c return None
11017
Test/png/11017.png
# Write a python function to find the maximum of two numbers. def maximum(a, b): if a >= b: return a else: return b
10688
Test/png/10688.png
def _regex_replacement(self, target, replacement): match = re.compile(target) self.data = match.sub(replacement, self.data)
11266
Test/png/11266.png
# Write a python function to find the digit distance between two integers. def digit_distance_nums(n1, n2): return sum(map(int, str(abs(n1 - n2))))
10844
Test/png/10844.png
# Write a function to calculate electricity bill. def cal_electbill(units): if units < 50: amount = units * 2.60 surcharge = 25 elif units <= 100: amount = 130 + ((units - 50) * 3.25) surcharge = 35 elif units <= 200: amount = 130 + 162.50 + ((units - 100) * 5.26) surcharge = 45 else: amount = 130 + 162.50 + 526 + ((units - 200) * 8.45) surcharge = 75 total = amount + surcharge return total
10553
Test/png/10553.png
def ensure_str(value): if isinstance(value, six.string_types): return value else: return six.text_type(value)
10452
Test/png/10452.png
def upload(self, docs_base, release): return getattr(self, '_to_' + self.target)(docs_base, release)
11104
Test/png/11104.png
# Write a function to check whether the given string starts and ends with the same character or not using regex. import re regex = r"^[a-z]$|^([a-z]).*\1$" def check_char(string): if re.search(regex, string): return "Valid" else: return "Invalid"
10592
Test/png/10592.png
def exact_sqrt(n2): "If n2 is a perfect square, return its square root, else raise error." n = int(math.sqrt(n2)) assert n * n == n2 return n
10327
Test/png/10327.png
def euclidean(c1, c2): diffs = ((i - j) for i, j in zip(c1, c2)) return sum(x * x for x in diffs)
10151
Test/png/10151.png
def data(fname): data_file = open(data_filename(fname)) try: return data_file.read() finally: data_file.close()
11131
Test/png/11131.png
# Write a function to solve gold mine problem. def get_maxgold(gold, m, n): goldTable = [[0 for i in range(n)] for j in range(m)] for col in range(n - 1, -1, -1): for row in range(m): if col == n - 1: right = 0 else: right = goldTable[row][col + 1] if row == 0 or col == n - 1: right_up = 0 else: right_up = goldTable[row - 1][col + 1] if row == m - 1 or col == n - 1: right_down = 0 else: right_down = goldTable[row + 1][col + 1] goldTable[row][col] = gold[row][col] + max(right, right_up, right_down) res = goldTable[0][0] for i in range(1, m): res = max(res, goldTable[i][0]) return res
10274
Test/png/10274.png
def get(self, list_id, segment_id): return self._mc_client._get(url=self._build_path(list_id, 'segments', segment_id))
10718
Test/png/10718.png
# Write a function to get the n smallest items from a dataset. import heapq def small_nnum(list1, n): smallest = heapq.nsmallest(n, list1) return smallest
10943
Test/png/10943.png
# Write a python function to set all even bits of a given number. def even_bit_set_number(n): count = 0 res = 0 temp = n while temp > 0: if count % 2 == 1: res |= 1 << count count += 1 temp >>= 1 return n | res
10210
Test/png/10210.png
def filter_bolts(table, header): bolts_info = [] for row in table: if row[0] == 'bolt': bolts_info.append(row) return bolts_info, header
10388
Test/png/10388.png
def disk(self): r = self.local_renderer r.run(r.env.disk_usage_command)
10488
Test/png/10488.png
def intersects(self, i): return self.start <= i.end and i.start <= self.end
10679
Test/png/10679.png
def redirect_to_env_paths(path): with open(path, 'r') as f: redirected = f.read() return shlex.split(redirected)
11259
Test/png/11259.png
# Write a function to extract a specified column from a given nested list. def extract_column(list1, n): result = [i.pop(n) for i in list1] return result
11276
Test/png/11276.png
# Write a function to create a list of empty dictionaries. def empty_list(length): empty_list = [{} for _ in range(length)] return empty_list