common_id
stringlengths
5
5
image
stringlengths
18
18
code
stringlengths
55
1.44k
10804
Test/png/10804.png
# Write a python function to find the number of divisors of a given integer. def divisor(n): for i in range(n): x = len([i for i in range(1, n + 1) if not n % i]) return x
10996
Test/png/10996.png
# Write a function to count array elements having modular inverse under given prime number p equal to itself. def modular_inverse(arr, N, P): current_element = 0 for i in range(0, N): if (arr[i] * arr[i]) % P == 1: current_element = current_element + 1 return current_element
10579
Test/png/10579.png
def is_variable(x): "A variable is an Expr with no args and a lowercase symbol as the op." return isinstance(x, Expr) and not x.args and is_var_symbol(x.op)
10378
Test/png/10378.png
def update(self, **kwargs): for name, value in kwargs.items(): setattr(self, name, value)
11101
Test/png/11101.png
# Write a function to find the list with maximum length using lambda function. def max_length_list(input_list): max_length = max(len(x) for x in input_list) max_list = max(input_list, key=lambda i: len(i)) return (max_length, max_list)
11182
Test/png/11182.png
# Write a function to replace characters in a string. def replace_char(str1, ch, newch): str2 = str1.replace(ch, newch) return str2
10945
Test/png/10945.png
# Write a function to check the occurrences of records which occur similar times in the given tuples. from collections import Counter def check_occurences(test_list): res = dict(Counter(tuple(ele) for ele in map(sorted, test_list))) return res
10901
Test/png/10901.png
# Write a function to remove the duplicates from the given tuple. def remove_tuple(test_tup): res = tuple(set(test_tup)) return res
11185
Test/png/11185.png
# Write a python function to convert the given string to lower case. def is_lower(string): return string.lower()
11083
Test/png/11083.png
# Write a function to round the given number to the nearest multiple of a specific number. def round_num(n, m): a = (n // m) * m b = a + m return b if n - a > b - n else a
10803
Test/png/10803.png
# Write a python function to find the minimum length of sublist. def Find_Min_Length(lst): minLength = min(len(x) for x in lst) return minLength
10264
Test/png/10264.png
def get_floating_ip(self, ip): return FloatingIP.get_object(api_token=self.token, ip=ip)
10143
Test/png/10143.png
def close(self): self.flush() setattr(sys, self.channel, self.ostream) self.file.close() self._closed = True
10349
Test/png/10349.png
def get_action_by_id(op, action_id): actions = get_actions(op) if actions and 1 <= action_id < len(actions): return actions[action_id - 1]
10862
Test/png/10862.png
# Write a function to extract every specified element from a given two dimensional list. def specified_element(nums, N): result = [i[N] for i in nums] return result
10580
Test/png/10580.png
def utility(self, state, player): "Return the value to player; 1 for win, -1 for loss, 0 otherwise." return if_(player == 'X', state.utility, -state.utility)
10966
Test/png/10966.png
# Write a function to find number of odd elements in the given list using lambda function. def count_odd(array_nums): count_odd = len(list(filter(lambda x: (x % 2 != 0), array_nums))) return count_odd
10819
Test/png/10819.png
# Write a function to find common elements in given nested lists. * list item * list item * list item * list item def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result
10983
Test/png/10983.png
# Write a python function to find the position of the last removed element from the given array. import math as mt def get_Position(a, n, m): for i in range(n): a[i] = a[i] // m + (a[i] % m != 0) result, maxx = -1, -1 for i in range(n - 1, -1, -1): if maxx < a[i]: maxx = a[i] result = i return result + 1
10487
Test/png/10487.png
def call(self, call_params): path = '/' + self.api_version + '/Call/' method = 'POST' return self.request(path, method, call_params)
10302
Test/png/10302.png
def send_packet(self, pkt): self.put_client_msg(packet.encode(pkt, self.json_dumps))
10343
Test/png/10343.png
def get_parm(self, key): if key in self.__parm.keys(): return self.__parm[key] return None
10930
Test/png/10930.png
# Write a function to check if all the elements in tuple have same data type or not. def check_type(test_tuple): res = True for ele in test_tuple: if not isinstance(ele, type(test_tuple[0])): res = False break return res
10753
Test/png/10753.png
# Write a function to find the gcd of the given array elements. def find_gcd(x, y): while y: x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
10482
Test/png/10482.png
def bik(): return '04' + \ ''.join([str(random.randint(1, 9)) for _ in range(5)]) + \ str(random.randint(0, 49) + 50)
11121
Test/png/11121.png
# Write a function to extract the nth element from a given list of tuples. def extract_nth_element(list1, n): result = [x[n] for x in list1] return result
10931
Test/png/10931.png
# Write a function to check for majority element in the given sorted array. def is_majority(arr, n, x): i = binary_search(arr, 0, n - 1, x) if i == -1: return False if ((i + n // 2) <= (n - 1)) and arr[i + n // 2] == x: return True else: return False def binary_search(arr, low, high, x): if high >= low: mid = (low + high) // 2 if (mid == 0 or x > arr[mid - 1]) and (arr[mid] == x): return mid elif x > arr[mid]: return binary_search(arr, (mid + 1), high, x) else: return binary_search(arr, low, (mid - 1), x) return -1
10683
Test/png/10683.png
def upstream_url(self, uri): "Returns the URL to the upstream data source for the given URI based on configuration" return self.application.options.upstream + self.request.uri
10384
Test/png/10384.png
def set_mappings(cls, index_name, doc_type, mappings): cache.set(cls.get_cache_item_name(index_name, doc_type), mappings)
10743
Test/png/10743.png
# Write a function to find the n-th rectangular number. def find_rect_num(n): return n * (n + 1)
10115
Test/png/10115.png
def memoize(f): cache = {} def memf(*x): if x not in cache: cache[x] = f(*x) return cache[x] return memf
11133
Test/png/11133.png
# Write a function to count the number of sublists containing a particular element. def count_element_in_list(list1, x): ctr = 0 for i in range(len(list1)): if x in list1[i]: ctr += 1 return ctr
10281
Test/png/10281.png
def _clip(sid, prefix): return sid[len(prefix):] if sid.startswith(prefix) else sid
11080
Test/png/11080.png
# Write a function to sort a given list of elements in ascending order using heap queue algorithm. import heapq as hq def heap_assending(nums): hq.heapify(nums) s_result = [hq.heappop(nums) for i in range(len(nums))] return s_result
10409
Test/png/10409.png
def piano_roll(annotation, **kwargs): times, midi = annotation.to_interval_values() return mir_eval.display.piano_roll(times, midi=midi, **kwargs)
10668
Test/png/10668.png
def foex(a, b): return (np.sum(a > b, dtype=float) / len(a) - 0.5) * 100
10717
Test/png/10717.png
# Write a python function to find the minimum number of rotations required to get the same string. def find_Rotations(str): tmp = str + str n = len(str) for i in range(1, n + 1): substring = tmp[i : i + n] if str == substring: return i return n
11012
Test/png/11012.png
# Write a python function to find element at a given index after number of rotations. def find_Element(arr, ranges, rotations, index): for i in range(rotations - 1, -1, -1): left = ranges[i][0] right = ranges[i][1] if left <= index and right >= index: if index == left: index = right else: index = index - 1 return arr[index]
11268
Test/png/11268.png
# Write a function to find the union of elements of the given tuples. def union_elements(test_tup1, test_tup2): res = tuple(set(test_tup1 + test_tup2)) return res
10213
Test/png/10213.png
def serialize_data_tuple(self, stream_id, latency_in_ns): self.update_count(self.TUPLE_SERIALIZATION_TIME_NS, incr_by=latency_in_ns, key=stream_id)
10716
Test/png/10716.png
# Write a function to find squares of individual elements in a list using lambda function. def square_nums(nums): square_nums = list(map(lambda x: x**2, nums)) return square_nums
10936
Test/png/10936.png
# Write a python function to check whether all the bits are unset in the given range or not. def all_Bits_Set_In_The_Given_Range(n, l, r): num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) new_num = n & num if new_num == 0: return True return False
10158
Test/png/10158.png
def print_bintree(tree, indent=' '): for n in sorted(tree.keys()): print("%s%s" % (indent * depth(n, tree), n))
11077
Test/png/11077.png
# Write a function to find the lateral surface area of cuboid def lateralsurface_cuboid(l, w, h): LSA = 2 * h * (l + w) return LSA
11150
Test/png/11150.png
# Write a function to find the ration of positive numbers in an array of integers. from array import array def positive_count(nums): n = len(nums) n1 = 0 for x in nums: if x > 0: n1 += 1 else: None return round(n1 / n, 2)
10967
Test/png/10967.png
# Write a function to maximize the given two tuples. def maximize_elements(test_tup1, test_tup2): res = tuple( tuple(max(a, b) for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2) ) return res
10123
Test/png/10123.png
def user_config_files(): return filter(os.path.exists, map(os.path.expanduser, config_files))
11246
Test/png/11246.png
# Write a python function to convert a given string list to a tuple. def string_list_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result
10827
Test/png/10827.png
# Write a python function to find the element that appears only once in a sorted array. def search(arr, n): XOR = 0 for i in range(n): XOR = XOR ^ arr[i] return XOR
11046
Test/png/11046.png
# Write a python function to count the number of substrings with same first and last characters. def check_Equality(s): return ord(s[0]) == ord(s[len(s) - 1]) def count_Substring_With_Equal_Ends(s): result = 0 n = len(s) for i in range(n): for j in range(1, n - i + 1): if check_Equality(s[i : i + j]): result += 1 return result
11253
Test/png/11253.png
# Write a python function to toggle only first and last bits of a given number. def take_L_and_F_set_bits(n): n = n | n >> 1 n = n | n >> 2 n = n | n >> 4 n = n | n >> 8 n = n | n >> 16 return ((n + 1) >> 1) + 1 def toggle_F_and_L_bits(n): if n == 1: return 0 return n ^ take_L_and_F_set_bits(n)
10696
Test/png/10696.png
def n_p(self): return 2*_sltr.GeV2joule(self.E)*_spc.epsilon_0 / (self.beta*_spc.elementary_charge)**2
10458
Test/png/10458.png
def _rows(self, spec): rows = self.new_row_collection() for row in spec: rows.append(self._row(row)) return rows
10164
Test/png/10164.png
def _warn(self, msg): self._warnings.append(msg) sys.stderr.write("Coverage.py warning: %s\n" % msg)
11198
Test/png/11198.png
# Write a function to extract all the pairs which are symmetric in the given tuple list. def extract_symmetric(test_list): temp = set(test_list) & {(b, a) for a, b in test_list} res = {(a, b) for a, b in temp if a < b} return res
10736
Test/png/10736.png
# Write a python function to find binomial co-efficient. def binomial_Coeff(n, k): if k > n: return 0 if k == 0 or k == n: return 1 return binomial_Coeff(n - 1, k - 1) + binomial_Coeff(n - 1, k)
10357
Test/png/10357.png
def is_cached(self, url): try: return True if url in self.cache else False except TypeError: return False
10914
Test/png/10914.png
# Write a function to perform the adjacent element concatenation in the given tuples. def concatenate_elements(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return res
10385
Test/png/10385.png
def output_error(msg): click.echo(click.style(msg, fg='red'), err=True)
11115
Test/png/11115.png
# Write a function to create the next bigger number by rearranging the digits of a given number. def rearrange_bigger(n): nums = list(str(n)) for i in range(len(nums) - 2, -1, -1): if nums[i] < nums[i + 1]: z = nums[i:] y = min(filter(lambda x: x > z[0], z)) z.remove(y) z.sort() nums[i:] = [y] + z return int("".join(nums)) return False
10900
Test/png/10900.png
# Write a python function to check whether a string has atleast one letter and one number. def check_String(str): flag_l = False flag_n = False for i in str: if i.isalpha(): flag_l = True if i.isdigit(): flag_n = True return flag_l and flag_n
10727
Test/png/10727.png
# Write a function to find whether a given array of integers contains any duplicate element. def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
10672
Test/png/10672.png
def remove(self): self.run_hook('preremove') utils.rmtree(self.path) self.run_hook('postremove')
11040
Test/png/11040.png
# Write a function to count character frequency of a given string. def char_frequency(str1): dict = {} for n in str1: keys = dict.keys() if n in keys: dict[n] += 1 else: dict[n] = 1 return dict
10946
Test/png/10946.png
# Write a python function to count number of non-empty substrings of a given string. def number_of_substrings(str): str_len = len(str) return int(str_len * (str_len + 1) / 2)
10275
Test/png/10275.png
def create(self, list_id, data): return self._mc_client._post(url=self._build_path(list_id, 'segments'), data=data)
10802
Test/png/10802.png
# Write a function to extract the index minimum value record from the given tuples. from operator import itemgetter def index_minimum(test_list): res = min(test_list, key=itemgetter(1))[0] return res
10471
Test/png/10471.png
def _smixins(self, name): return (self._mixins[name] if name in self._mixins else False)
11086
Test/png/11086.png
# Write a python function to shift last element to first position in the given list. def move_first(test_list): test_list = test_list[-1:] + test_list[:-1] return test_list
11030
Test/png/11030.png
# Write a function to find all index positions of the minimum values in a given list. def position_min(list1): min_val = min(list1) min_result = [i for i, j in enumerate(list1) if j == min_val] return min_result
10352
Test/png/10352.png
def get_action_image(op, name): action = _get_action_by_name(op, name) if action: return action.get('imageUri')
10390
Test/png/10390.png
def initialize(self, executor, secret): self.executor = executor self.secret = secret
10208
Test/png/10208.png
def get_java_path(): java_home = os.environ.get("JAVA_HOME") return os.path.join(java_home, BIN_DIR, "java")
10290
Test/png/10290.png
def _on_typing(self, typing_message): self._typing_statuses[typing_message.user_id] = typing_message.status self._update()
10136
Test/png/10136.png
def unregister_transformer(self, transformer): if transformer in self._transformers: self._transformers.remove(transformer)
11003
Test/png/11003.png
# Write a function to return the sum of all divisors of a number. def sum_div(number): divisors = [1] for i in range(2, number): if (number % i) == 0: divisors.append(i) return sum(divisors)
10772
Test/png/10772.png
# Write a function to sort a list of tuples using lambda. def subject_marks(subjectmarks): # subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key=lambda x: x[1]) return subjectmarks
11165
Test/png/11165.png
# Write a python function to find the sublist having minimum length. def Find_Min(lst): minList = min((x) for x in lst) return minList
11156
Test/png/11156.png
# Write a function to calculate the sum of perrin numbers. def cal_sum(n): a = 3 b = 0 c = 2 if n == 0: return 3 if n == 1: return 3 if n == 2: return 5 sum = 5 while n > 2: d = a + b sum = sum + d a = b b = c c = d n = n - 1 return sum
10528
Test/png/10528.png
def _setRTSDTR(port, RTS, DTR): port.setRTS(RTS) port.setDTR(DTR)
11205
Test/png/11205.png
# Write a function to find the surface area of a cone. import math def surfacearea_cone(r, h): l = math.sqrt(r * r + h * h) SA = math.pi * r * (r + l) return SA
10506
Test/png/10506.png
def get_homes(self, only_active=True): return [self.get_home(home_id) for home_id in self.get_home_ids(only_active)]
10859
Test/png/10859.png
# Write a python function to check whether the given number is co-prime or not. def gcd(p, q): while q != 0: p, q = q, p % q return p def is_coprime(x, y): return gcd(x, y) == 1
10450
Test/png/10450.png
def provider(workdir, commit=True, **kwargs): return SCM_PROVIDER[auto_detect(workdir)](workdir, commit=commit, **kwargs)
11074
Test/png/11074.png
# Write a python function to find the largest product of the pair of adjacent elements from a given list of integers. def adjacent_num_product(list_nums): return max(a * b for a, b in zip(list_nums, list_nums[1:]))
10111
Test/png/10111.png
def _append_png(self, png, before_prompt=False): self._append_custom(self._insert_png, png, before_prompt)
10595
Test/png/10595.png
def connect1(self, A, B, distance): "Add a link from A to B of given distance, in one direction only." self.dict.setdefault(A, {})[B] = distance
10970
Test/png/10970.png
# Write a function to split a given list into two parts where the length of the first part of the list is given. def split_two_parts(list1, L): return list1[:L], list1[L:]
11071
Test/png/11071.png
# Write a function to add the k elements to each element in the tuple. def add_K_element(test_list, K): res = [tuple(j + K for j in sub) for sub in test_list] return res
11231
Test/png/11231.png
# Write a function to check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda function. def check_string(str1): messg = [ lambda str1: any(x.isupper() for x in str1) or "String must have 1 upper case character.", lambda str1: any(x.islower() for x in str1) or "String must have 1 lower case character.", lambda str1: any(x.isdigit() for x in str1) or "String must have 1 number.", lambda str1: len(str1) >= 7 or "String length should be atleast 8.", ] result = [x for x in [i(str1) for i in messg] if x != True] if not result: result.append("Valid string.") return result
10661
Test/png/10661.png
def dinner(self, message="Dinner is served", shout: bool = False): return self.helper.output(message, shout)
10541
Test/png/10541.png
def param_particle_pos(self, ind): ind = self._vps(listify(ind)) return [self._i2p(i, j) for i in ind for j in ['z', 'y', 'x']]
11175
Test/png/11175.png
# Write a python function to convert decimal number to octal number. def decimal_to_Octal(deciNum): octalNum = 0 countval = 1 dNo = deciNum while deciNum != 0: remainder = deciNum % 8 octalNum += remainder * countval countval = countval * 10 deciNum //= 8 return octalNum
10493
Test/png/10493.png
def count_sequences(infile): seq_reader = sequences.file_reader(infile) n = 0 for seq in seq_reader: n += 1 return n
11186
Test/png/11186.png
# Write a function to remove lowercase substrings from a given string. import re def remove_lowercase(str1): remove_lower = lambda text: re.sub("[a-z]", "", text) result = remove_lower(str1) return result
10477
Test/png/10477.png
def year(past=False, min_delta=0, max_delta=20): return dt.date.today().year + _delta(past, min_delta, max_delta)
10777
Test/png/10777.png
# Write a function to check whether a list contains the given sublist or not. def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i + n] == s[n]): n += 1 if n == len(s): sub_set = True return sub_set
10159
Test/png/10159.png
def allreduce(self, f, value, flat=True): return self.reduce(f, value, flat=flat, all=True)
11149
Test/png/11149.png
# Write a function to find the surface area of a cube. def surfacearea_cube(l): surfacearea = 6 * l * l return surfacearea
10222
Test/png/10222.png
def ConstructArray(self, py_arr): arr = self.NewArray(len(py_arr)) arr._init(py_arr) return arr