common_id
stringlengths
5
5
image
stringlengths
18
18
code
stringlengths
55
1.44k
10890
Test/png/10890.png
# Write a function to find uppercase, lowercase, special character and numeric values using regex. import re def find_character(string): uppercase_characters = re.findall(r"[A-Z]", string) lowercase_characters = re.findall(r"[a-z]", string) numerical_characters = re.findall(r"[0-9]", string) special_characters = re.findall(r"[, .!?]", string) return ( uppercase_characters, lowercase_characters, numerical_characters, special_characters, )
10235
Test/png/10235.png
def GT(self, a, b): return Operators.ITEBV(256, Operators.UGT(a, b), 1, 0)
10408
Test/png/10408.png
def Async(cls, token, session=None, **options): return cls(token, session=session, is_async=True, **options)
10609
Test/png/10609.png
def algo_exp(x, m, t, b): return m*np.exp(-t*x)+b
10438
Test/png/10438.png
def switch(template, version): temple.update.update(new_template=template, new_version=version)
10887
Test/png/10887.png
# Write a function to find if the given number is a keith number or not. def is_num_keith(x): terms = [] temp = x n = 0 while temp > 0: terms.append(temp % 10) temp = int(temp / 10) n += 1 terms.reverse() next_term = 0 i = n while next_term < x: next_term = 0 for j in range(1, n + 1): next_term += terms[i - j] terms.append(next_term) i += 1 return next_term == x
10144
Test/png/10144.png
def write(self, data): self.file.write(data) self.ostream.write(data) self.ostream.flush()
10314
Test/png/10314.png
def guid(self, guid): return self._json(self._get(self._build_url('guids', guid)), 200)['data']['type']
10124
Test/png/10124.png
def remove_task(message): task = Task.objects.get(pk=message['id']) task.delete()
11179
Test/png/11179.png
# Write a python function to find remainder of array multiplication divided by n. def find_remainder(arr, lens, n): mul = 1 for i in range(lens): mul = (mul * (arr[i] % n)) % n return mul % n
11018
Test/png/11018.png
# Write a function to convert a given string to a tuple. def string_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result
10593
Test/png/10593.png
def expand(self, problem): "List the nodes reachable in one step from this node." return [self.child_node(problem, action) for action in problem.actions(self.state)]
10607
Test/png/10607.png
def abfIDfromFname(fname): fname = os.path.abspath(fname) basename = os.path.basename(fname) return os.path.splitext(basename)[0]
10816
Test/png/10816.png
# Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm. import heapq def merge_sorted_list(num1, num2, num3): num1 = sorted(num1) num2 = sorted(num2) num3 = sorted(num3) result = heapq.merge(num1, num2, num3) return list(result)
11167
Test/png/11167.png
# Write a function to remove uppercase substrings from a given string by using regex. import re def remove_uppercase(str1): remove_upper = lambda text: re.sub("[A-Z]", "", text) result = remove_upper(str1) return result
11159
Test/png/11159.png
# Write a function to remove all whitespaces from the given string using regex. import re def remove_whitespaces(text1): return re.sub(r"\s+", "", text1)
11028
Test/png/11028.png
# Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers. def sum_difference(n): sumofsquares = 0 squareofsum = 0 for num in range(1, n + 1): sumofsquares += num * num squareofsum += num squareofsum = squareofsum**2 return squareofsum - sumofsquares
10811
Test/png/10811.png
# Write a function to find eulerian number a(n, m). def eulerian_num(n, m): if m >= n or n == 0: return 0 if m == 0: return 1 return (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)
10556
Test/png/10556.png
def release(self): self._lock.release() with self._stat_lock: self._locked = False self._last_released = datetime.now()
10251
Test/png/10251.png
def f7(seq): seen = set() seen_add = seen.add return [x for x in seq if x not in seen and not seen_add(x)]
11092
Test/png/11092.png
# Write a python function to find the frequency of the smallest value in a given array. def frequency_Of_Smallest(n, arr): mn = arr[0] freq = 1 for i in range(1, n): if arr[i] < mn: mn = arr[i] freq = 1 elif arr[i] == mn: freq += 1 return freq
10773
Test/png/10773.png
# Write a function of recursion list sum. def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
10947
Test/png/10947.png
# Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m. def get_total_number_of_sequences(m, n): T = [[0 for i in range(n + 1)] for i in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0 or j == 0: T[i][j] = 0 elif i < j: T[i][j] = 0 elif j == 1: T[i][j] = i else: T[i][j] = T[i - 1][j] + T[i // 2][j - 1] return T[m][n]
10145
Test/png/10145.png
def add_new_heart_handler(self, handler): self.log.debug("heartbeat::new_heart_handler: %s", handler) self._new_handlers.add(handler)
10858
Test/png/10858.png
# Write a python function to find whether the given number is present in the infinite sequence or not. def does_Contain_B(a, b, c): if a == b: return True if (b - a) * c > 0 and (b - a) % c == 0: return True return False
10359
Test/png/10359.png
def clone(self): return StreamThrottle( read=self.read.clone(), write=self.write.clone() )
10270
Test/png/10270.png
def cmd_join(opts): config = load_config(opts.config) b = get_blockade(config, opts) b.join()
11024
Test/png/11024.png
# Write a function to find the index of the last occurrence of a given number in a sorted array. def find_last_occurrence(A, x): (left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid left = mid + 1 elif x < A[mid]: right = mid - 1 else: left = mid + 1 return result
11256
Test/png/11256.png
# Write a function to find the length of the longest increasing subsequence of the given sequence. def longest_increasing_subsequence(arr): n = len(arr) longest_increasing_subsequence = [1] * n for i in range(1, n): for j in range(0, i): if ( arr[i] > arr[j] and longest_increasing_subsequence[i] < longest_increasing_subsequence[j] + 1 ): longest_increasing_subsequence[i] = ( longest_increasing_subsequence[j] + 1 ) maximum = 0 for i in range(n): maximum = max(maximum, longest_increasing_subsequence[i]) return maximum
10994
Test/png/10994.png
# Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times. def max_sub_array_sum_repeated(a, n, k): max_so_far = -2147483648 max_ending_here = 0 for i in range(n * k): max_ending_here = max_ending_here + a[i % n] if max_so_far < max_ending_here: max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 return max_so_far
10648
Test/png/10648.png
def save(self): if len(self) == 0: return [] mdl = self.getModel() return mdl.saver.save(self)
11161
Test/png/11161.png
# Write a python function to find the sum of even factors of a number. import math def sumofFactors(n): if n % 2 != 0: return 0 res = 1 for i in range(2, (int)(math.sqrt(n)) + 1): count = 0 curr_sum = 1 curr_term = 1 while n % i == 0: count = count + 1 n = n // i if i == 2 and count == 1: curr_sum = 0 curr_term = curr_term * i curr_sum = curr_sum + curr_term res = res * curr_sum if n >= 2: res = res * (1 + n) return res
10351
Test/png/10351.png
def get_action_environment(op, name): action = _get_action_by_name(op, name) if action: return action.get('environment')
10614
Test/png/10614.png
def iso_reference_isvalid(ref): ref = str(ref) cs_source = ref[4:] + ref[:4] return (iso_reference_str2int(cs_source) % 97) == 1
10864
Test/png/10864.png
# Write a function to convert a tuple of string values to a tuple of integer values. def tuple_int_str(tuple_str): result = tuple((int(x[0]), int(x[1])) for x in tuple_str) return result
10354
Test/png/10354.png
def discover(cls): file = os.path.join(Config.config_dir, Config.config_name) return cls.from_file(file)
10660
Test/png/10660.png
def lunch(self, message="Time for lunch", shout: bool = False): return self.helper.output(message, shout)
10418
Test/png/10418.png
def error(message): global parser print(_("Error: ") + message) print() parser.print_help() sys.exit()
10168
Test/png/10168.png
def get_url_args(url): url_data = urllib.parse.urlparse(url) arg_dict = urllib.parse.parse_qs(url_data.query) return arg_dict
11130
Test/png/11130.png
# Write a python function to find the average of cubes of first n natural numbers. def find_Average_Of_Cube(n): sum = 0 for i in range(1, n + 1): sum += i * i * i return round(sum / n, 6)
10431
Test/png/10431.png
def sorted(list, cmp=None, reversed=False): list = [x for x in list] list.sort(cmp) if reversed: list.reverse() return list
10547
Test/png/10547.png
def get(self): fields = [c.get() for c in self.comps] return self.field_reduce_func(fields)
10685
Test/png/10685.png
def addMenu(self): self.parent.multiLogLayout.addLayout(self.logSelectLayout) self.getPrograms(logType, programName)
10775
Test/png/10775.png
# Write a function to find the number of ways to partition a set of bell numbers. def bell_number(n): bell = [[0 for i in range(n + 1)] for j in range(n + 1)] bell[0][0] = 1 for i in range(1, n + 1): bell[i][0] = bell[i - 1][i - 1] for j in range(1, i + 1): bell[i][j] = bell[i - 1][j - 1] + bell[i][j - 1] return bell[n][0]
10481
Test/png/10481.png
def account_number(): account = [random.randint(1, 9) for _ in range(20)] return "".join(map(str, account))
10193
Test/png/10193.png
def time(self): "Return the time part, with tzinfo None." return time(self.hour, self.minute, self.second, self.microsecond)
10283
Test/png/10283.png
def stop_scan(self, timeout_sec=TIMEOUT_SEC): get_provider()._central_manager.stopScan() self._is_scanning = False
11174
Test/png/11174.png
# Write a function to find the peak element in the given array. def find_peak_util(arr, low, high, n): mid = low + (high - low) / 2 mid = int(mid) if (mid == 0 or arr[mid - 1] <= arr[mid]) and ( mid == n - 1 or arr[mid + 1] <= arr[mid] ): return mid elif mid > 0 and arr[mid - 1] > arr[mid]: return find_peak_util(arr, low, (mid - 1), n) else: return find_peak_util(arr, (mid + 1), high, n) def find_peak(arr, n): return find_peak_util(arr, 0, n - 1, n)
10298
Test/png/10298.png
def url_from_path(path): if os.sep != '/': path = '/'.join(path.split(os.sep)) return quote(path)
11277
Test/png/11277.png
# Write a function to sort each sublist of strings in a given list of lists. def sort_sublists(list1): result = list(map(sorted, list1)) return result
10776
Test/png/10776.png
# Write a python function to check whether the given array is monotonic or not. def is_Monotonic(A): return all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all( A[i] >= A[i + 1] for i in range(len(A) - 1) )
10367
Test/png/10367.png
def filter(self, x): y = signal.lfilter(self.b, [1], x) return y
11039
Test/png/11039.png
# Write a python function to count unset bits of a given number. def count_unset_bits(n): count = 0 x = 1 while x < n + 1: if (x & n) == 0: count += 1 x = x << 1 return count
10637
Test/png/10637.png
def labels(self): return sorted(self.channels, key=lambda c: self.channels[c])
11196
Test/png/11196.png
# Write a function to find the area of a pentagon. import math def area_pentagon(a): area = (math.sqrt(5 * (5 + 2 * math.sqrt(5))) * pow(a, 2)) / 4.0 return area
11286
Test/png/11286.png
# Write a function to interleave lists of the same length. def interleave_lists(list1, list2, list3): result = [el for pair in zip(list1, list2, list3) for el in pair] return result
10729
Test/png/10729.png
# Write a function to find m number of multiples of n. def multiples_of_num(m, n): multiples_of_num = list(range(n, (m + 1) * n, n)) return list(multiples_of_num)
10948
Test/png/10948.png
# Write a function to replace the last element of the list with another list. def replace_list(list1, list2): list1[-1:] = list2 replace_list = list1 return replace_list
10311
Test/png/10311.png
def destroy(self): self.ws.destroy() self.bot.remove_listener(self.on_socket_response) self.hooks.clear()
10513
Test/png/10513.png
def execute(helper, config, args): helper.wait_for_environments(args.environment, health=args.health)
10665
Test/png/10665.png
def rmse(a, b): return np.sqrt(np.square(a - b).mean())
10702
Test/png/10702.png
def handle_data(self, data): if data.strip(): data = djeffify_string(data) self.djhtml += data
10913
Test/png/10913.png
# Write a function to find the inversions of tuple elements in the given tuple list. def inversion_elements(test_tup): res = tuple(list(map(lambda x: ~x, list(test_tup)))) return res
11013
Test/png/11013.png
# Write a function to match two words from a list of words starting with letter 'p'. import re def start_withp(words): for w in words: m = re.match("(P\w+)\W(P\w+)", w) if m: return m.groups()
11032
Test/png/11032.png
# Write a function to extract the sum of alternate chains of tuples. def sum_of_alternates(test_tuple): sum1 = 0 sum2 = 0 for idx, ele in enumerate(test_tuple): if idx % 2: sum1 += ele else: sum2 += ele return ((sum1), (sum2))
10839
Test/png/10839.png
# Write a python function to reverse only the vowels of a given string. def reverse_vowels(str1): vowels = "" for char in str1: if char in "aeiouAEIOU": vowels += char result_string = "" for char in str1: if char in "aeiouAEIOU": result_string += vowels[-1] vowels = vowels[:-1] else: result_string += char return result_string
10265
Test/png/10265.png
def get_volume(self, volume_id): return Volume.get_object(api_token=self.token, volume_id=volume_id)
11000
Test/png/11000.png
# Write a python function to find quotient of two numbers. def find(n, m): q = n // m return q
10971
Test/png/10971.png
# Write a function to merge two dictionaries. def merge_dict(d1, d2): d = d1.copy() d.update(d2) return d
10430
Test/png/10430.png
def reverse(self): colors = ColorList.copy(self) _list.reverse(colors) return colors
10353
Test/png/10353.png
def format_pairs(self, values): return ', '.join( '%s=%s' % (key, value) for key, value in sorted(values.items()))
11199
Test/png/11199.png
# Write a function to find the sum of geometric progression series. import math def sum_gp(a, n, r): total = (a * (1 - math.pow(r, n))) / (1 - r) return total
10993
Test/png/10993.png
# Write a function that matches a string that has an a followed by two to three 'b'. import re def text_match_two_three(text): patterns = "ab{2,3}" if re.search(patterns, text): return "Found a match!" else: return "Not matched!"
10794
Test/png/10794.png
# Write a function to find nth centered hexagonal number. def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
11248
Test/png/11248.png
# Write a python function to find the difference between highest and least frequencies in a given array. def find_Diff(arr, n): arr.sort() count = 0 max_count = 0 min_count = n for i in range(0, (n - 1)): if arr[i] == arr[i + 1]: count += 1 continue else: max_count = max(max_count, count) min_count = min(min_count, count) count = 0 return max_count - min_count
11134
Test/png/11134.png
# Write a function to filter odd numbers using lambda function. def filter_oddnumbers(nums): odd_nums = list(filter(lambda x: x % 2 != 0, nums)) return odd_nums
10572
Test/png/10572.png
def getnodefor(self, name): "Return the node where the ``name`` would land to" node = self._getnodenamefor(name) return {node: self.cluster['nodes'][node]}
10514
Test/png/10514.png
def commit(self, *args, **kwargs): return super(Deposit, self).commit(*args, **kwargs)
10705
Test/png/10705.png
def FromJsonString(self, value): self.Clear() for path in value.split(','): self.paths.append(path)
11228
Test/png/11228.png
# Write a function to find the lcm of the given array elements. def find_lcm(num1, num2): if num1 > num2: num = num1 den = num2 else: num = num2 den = num1 rem = num % den while rem != 0: num = den den = rem rem = num % den gcd = den lcm = int(int(num1 * num2) / int(gcd)) return lcm def get_lcm(l): num1 = l[0] num2 = l[1] lcm = find_lcm(num1, num2) for i in range(2, len(l)): lcm = find_lcm(lcm, l[i]) return lcm
10285
Test/png/10285.png
def clubStaff(self): method = 'GET' url = 'club/stats/staff' rc = self.__request__(method, url) return rc
10624
Test/png/10624.png
def abs_img(img): bool_img = np.abs(read_img(img).get_data()) return bool_img.astype(int)
10147
Test/png/10147.png
def get_ipython_package_dir(): ipdir = os.path.dirname(IPython.__file__) return py3compat.cast_unicode(ipdir, fs_encoding)
11136
Test/png/11136.png
# Write a function to sort the given array by using shell sort. def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list
10712
Test/png/10712.png
# Write a function to find the largest integers from a given list of numbers using heap queue algorithm. import heapq as hq def heap_queue_largest(nums, n): largest_nums = hq.nlargest(n, nums) return largest_nums
10587
Test/png/10587.png
def restore(self, removals): "Undo a supposition and all inferences from it." for B, b in removals: self.curr_domains[B].append(b)
10854
Test/png/10854.png
# Write a function to find the ascii value of total characters in a string. def ascii_value_string(str1): for i in range(len(str1)): return ord(str1[i])
10221
Test/png/10221.png
def _set_name(self, name): if self.own.get('name'): self.func_name = name self.own['name']['value'] = Js(name)
11043
Test/png/11043.png
# Write a function to find the sum of arithmetic progression. def ap_sum(a, n, d): total = (n * (2 * a + (n - 1) * d)) / 2 return total
10508
Test/png/10508.png
def _ratio_metric(v1, v2, **_kwargs): return (((v1 - v2) / (v1 + v2)) ** 2) if v1 + v2 != 0 else 0
10451
Test/png/10451.png
def fail(message, exitcode=1): sys.stderr.write('ERROR: {}\n'.format(message)) sys.stderr.flush() sys.exit(exitcode)
10942
Test/png/10942.png
# Write a function to find the volume of a cube. def volume_cube(l): volume = l * l * l return volume
10424
Test/png/10424.png
def _density(self): return 2.0*len(self.edges) / (len(self.nodes) * (len(self.nodes)-1))
11084
Test/png/11084.png
# Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value. def remove_replica(test_tup): temp = set() res = tuple( ele if ele not in temp and not temp.add(ele) else "MSP" for ele in test_tup ) return res
10693
Test/png/10693.png
def determine_type(x): types = (int, float, str) _type = filter(lambda a: is_type(a, x), types)[0] return _type(x)
10422
Test/png/10422.png
def copy(self, graph): l = self.__class__(graph, self.n) l.i = 0 return l
10360
Test/png/10360.png
def get_hash(x): if isinstance(x, str): return hash(x) elif isinstance(x, dict): return hash(yaml.dump(x))
11221
Test/png/11221.png
# Write a function to convert tuple into list by adding the given string after every element. def add_str(test_tup, K): res = [ele for sub in test_tup for ele in (sub, K)] return res
10296
Test/png/10296.png
def save_file(self): with open(self.write_file, 'w') as out_nb: json.dump(self.work_notebook, out_nb, indent=2)
11235
Test/png/11235.png
# Write a function to find all pairs in an integer array whose sum is equal to a given number. def get_pairs_count(arr, n, sum): count = 0 for i in range(0, n): for j in range(i + 1, n): if arr[i] + arr[j] == sum: count += 1 return count