common_id
stringlengths
5
5
image
stringlengths
18
18
code
stringlengths
55
1.44k
10454
Test/png/10454.png
def info(msg): _flush() sys.stdout.write(msg + '\n') sys.stdout.flush()
11280
Test/png/11280.png
# Write a python function to remove two duplicate numbers from a given number of lists. def two_unique_nums(nums): return [i for i in nums if nums.count(i) == 1]
11247
Test/png/11247.png
# Write a function to create a list containing the power of said number in bases raised to the corresponding number in the index using map function. def basesnum_coresspondingnum(bases_num, index): result = list(map(pow, bases_num, index)) return result
10740
Test/png/10740.png
# Write a python function to find the largest prime factor of a given number. import math def max_Prime_Factors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
11067
Test/png/11067.png
# Write a python function to check whether one root of the quadratic equation is twice of the other or not. def Check_Solution(a, b, c): if 2 * b * b == 9 * a * c: return "Yes" else: return "No"
10153
Test/png/10153.png
def file_matches(filename, patterns): return any(fnmatch.fnmatch(filename, pat) for pat in patterns)
10240
Test/png/10240.png
def _get_certificate(self, cfgstr=None): certificate = self.cacher.tryload(cfgstr=cfgstr) return certificate
10544
Test/png/10544.png
def update_function(self, param_vals): self.opt_obj.update_function(param_vals) return self.opt_obj.get_error()
10904
Test/png/10904.png
# Write a function to remove all the tuples with length k. def remove_tuples(test_list, K): res = [ele for ele in test_list if len(ele) != K] return res
10599
Test/png/10599.png
def consistent_with(event, evidence): "Is event consistent with the given evidence?" return every(lambda k, v: evidence.get(k, v) == v,event.items())
11029
Test/png/11029.png
# Write a function to find the demlo number for the given number. def find_demlo(s): l = len(s) res = "" for i in range(1, l + 1): res = res + str(i) for i in range(l - 1, 0, -1): res = res + str(i) return res
11237
Test/png/11237.png
# Write a function to find the nth jacobsthal-lucas number. def jacobsthal_lucas(n): dp = [0] * (n + 1) dp[0] = 2 dp[1] = 1 for i in range(2, n + 1): dp[i] = dp[i - 1] + 2 * dp[i - 2] return dp[n]
11289
Test/png/11289.png
# Write a python function to find the surface area of the square pyramid. def surface_Area(b, s): return 2 * b * s + pow(b, 2)
11085
Test/png/11085.png
# Write a python function to remove all occurrences of a character in a given string. def remove_Char(s, c): counts = s.count(c) s = list(s) while counts: s.remove(c) counts -= 1 s = "".join(s) return s
11152
Test/png/11152.png
# Write a function to trim each tuple by k in the given tuple list. def trim_tuple(test_list, K): res = [] for ele in test_list: N = len(ele) res.append(tuple(list(ele)[K : N - K])) return str(res)
10787
Test/png/10787.png
# Write a python function to check whether the length of the word is odd or not. def word_len(s): s = s.split(" ") for word in s: if len(word) % 2 != 0: return True else: return False
11234
Test/png/11234.png
# Write a python function to capitalize first and last letters of each word of a given string. def capitalize_first_last_letters(str1): str1 = result = str1.title() result = "" for word in str1.split(): result += word[:-1] + word[-1].upper() + " " return result[:-1]
10309
Test/png/10309.png
def stop(self): await self._lavalink.ws.send(op='stop', guildId=self.guild_id) self.current = None
10156
Test/png/10156.png
def get_msg(self, block=True, timeout=None): "Gets a message if there is one that is ready." return self._in_queue.get(block, timeout)
10446
Test/png/10446.png
def set(self, model, value): self.validate(value) self._pop(model) value = self.serialize(value) model.tags.append(value)
10295
Test/png/10295.png
def _numpy_solver(A, B): x = numpy.linalg.solve(A, B) return x
11065
Test/png/11065.png
# Write a function to find the maximum element of all the given tuple records. def find_max(test_list): res = max(int(j) for i in test_list for j in i) return res
11169
Test/png/11169.png
# Write a python function to count the upper case characters in a given string. def upper_ctr(str): upper_ctr = 0 for i in range(len(str)): if str[i] >= "A" and str[i] <= "Z": upper_ctr += 1 return upper_ctr
10495
Test/png/10495.png
def eof(fd): b = fd.read(1) end = len(b) == 0 if not end: curpos = fd.tell() fd.seek(curpos - 1) return end
10898
Test/png/10898.png
# Write a python function to count the number of integral co-ordinates that lie inside a square. def count_Intgral_Points(x1, y1, x2, y2): return (y2 - y1 - 1) * (x2 - x1 - 1)
10793
Test/png/10793.png
# Write a function to find the surface area of a sphere. import math def surfacearea_sphere(r): surfacearea = 4 * math.pi * r * r return surfacearea
10548
Test/png/10548.png
def set_shape(self, shape, inner): for c in self.comps: c.set_shape(shape, inner)
10464
Test/png/10464.png
def B(self): return unvec(self._vecB.value, (self.X.shape[1], self.A.shape[0]))
10191
Test/png/10191.png
def bitsToString(arr): s = array('c', '.'*len(arr)) for i in xrange(len(arr)): if arr[i] == 1: s[i] = '*' return s
10786
Test/png/10786.png
# Write a python function to find number of integers with odd number of set bits. def count_With_Odd_SetBits(n): if n % 2 != 0: return (n + 1) / 2 count = bin(n).count("1") ans = n / 2 if count % 2 != 0: ans += 1 return ans
10682
Test/png/10682.png
def ensure_path_exists(path, *args): if os.path.exists(path): return os.makedirs(path, *args)
10179
Test/png/10179.png
def getInputNames(self): inputs = self.getSpec().inputs return [inputs.getByIndex(i)[0] for i in xrange(inputs.getCount())]
11079
Test/png/11079.png
# Write a function to find the smallest missing element in a sorted array. def smallest_missing(A, left_element, right_element): if left_element > right_element: return left_element mid = left_element + (right_element - left_element) // 2 if A[mid] == mid: return smallest_missing(A, mid + 1, right_element) else: return smallest_missing(A, left_element, mid - 1)
10185
Test/png/10185.png
def getData(self, n): records = [self.getNext() for x in range(n)] return records
10806
Test/png/10806.png
# Write a function to multiply all the numbers in a list and divide with the length of the list. def multiply_num(numbers): total = 1 for x in numbers: total *= x return total / len(numbers)
10391
Test/png/10391.png
def data(self, X=None, y=None, sentences=None): self.X = X self.y = y self.sentences = sentences
11155
Test/png/11155.png
# Write a function to find cubes of individual elements in a list using lambda function. def cube_nums(nums): cube_nums = list(map(lambda x: x**3, nums)) return cube_nums
10457
Test/png/10457.png
def compile_glob(spec): parsed = "".join(parse_glob(spec)) regex = "^{0}$".format(parsed) return re.compile(regex)
10961
Test/png/10961.png
# Write a python function to count integers from a given list. def count_integer(list1): ctr = 0 for i in list1: if isinstance(i, int): ctr = ctr + 1 return ctr
10104
Test/png/10104.png
def select_down(self): r, c = self._index self._select_index(r+1, c)
10504
Test/png/10504.png
def use_parser(self, parsername): self.__parser = self.parsers[parsername] self.__parser()
10990
Test/png/10990.png
# Write a function to substaract two lists using map and lambda function. def sub_list(nums1, nums2): result = map(lambda x, y: x - y, nums1, nums2) return list(result)
10286
Test/png/10286.png
def to_participantid(user_id): return hangouts_pb2.ParticipantId( chat_id=user_id.chat_id, gaia_id=user_id.gaia_id )
10659
Test/png/10659.png
def breakfast(self, message="Breakfast is ready", shout: bool = False): return self.helper.output(message, shout)
10534
Test/png/10534.png
def query_by_user(cls, user, **kwargs): return cls._filter( cls.query.filter_by(user_id=user.get_id()), **kwargs )
10316
Test/png/10316.png
def fillCircle(self, x0, y0, r, color=None): md.fill_circle(self.set, x0, y0, r, color)
10435
Test/png/10435.png
def _invert(h): "Cheap function to invert a hash." i = {} for k, v in h.items(): i[v] = k return i
11151
Test/png/11151.png
# Write a python function to find the largest negative number from the given list. def largest_neg(list1): max = list1[0] for x in list1: if x < max: max = x return max
10935
Test/png/10935.png
# Write a function to find minimum of three numbers. def min_of_three(a, b, c): if (a <= b) and (a <= c): smallest = a elif (b <= a) and (b <= c): smallest = b else: smallest = c return smallest
10442
Test/png/10442.png
def create_project_thread(session, member_ids, project_id, message): return create_thread(session, member_ids, 'project', project_id, message)
11088
Test/png/11088.png
# Write a function to generate a two-dimensional array. def multi_list(rownum, colnum): multi_list = [[0 for col in range(colnum)] for row in range(rownum)] for row in range(rownum): for col in range(colnum): multi_list[row][col] = row * col return multi_list
10387
Test/png/10387.png
def _send_cmd(self, cmd): self._process.stdin.write("{}\n".format(cmd).encode("utf-8")) self._process.stdin.flush()
11244
Test/png/11244.png
# Write a function to select the nth items of a list. def nth_items(list, n): return list[::n]
11177
Test/png/11177.png
# Write a function to find the maximum profit earned from a maximum of k stock transactions def max_profit(price, k): n = len(price) final_profit = [[None for x in range(n)] for y in range(k + 1)] for i in range(k + 1): for j in range(n): if i == 0 or j == 0: final_profit[i][j] = 0 else: max_so_far = 0 for x in range(j): curr_price = price[j] - price[x] + final_profit[i - 1][x] if max_so_far < curr_price: max_so_far = curr_price final_profit[i][j] = max(final_profit[i][j - 1], max_so_far) return final_profit[k][n - 1]
10997
Test/png/10997.png
# Write a python function to calculate the number of odd days in a given year. def odd_Days(N): hund1 = N // 100 hund4 = N // 400 leap = N >> 2 ordd = N - leap if hund1: ordd += hund1 leap -= hund1 if hund4: ordd -= hund4 leap += hund4 days = ordd + leap * 2 odd = days % 7 return odd
10764
Test/png/10764.png
# Write a python function to check if a given number is one less than twice its reverse. def rev(num): rev_num = 0 while num > 0: rev_num = rev_num * 10 + num % 10 num = num // 10 return rev_num def check(n): return 2 * rev(n) == n + 1
11036
Test/png/11036.png
# Write a function to rotate a given list by specified number of items to the left direction. def rotate_left(list1, m, n): result = list1[m:] + list1[:n] return result
10509
Test/png/10509.png
def copy(self, space=None, name=None): return Cells(space=space, name=name, formula=self.formula)
11127
Test/png/11127.png
# Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list. def round_and_sum(list1): lenght = len(list1) round_and_sum = sum(list(map(round, list1)) * lenght) return round_and_sum
10250
Test/png/10250.png
def read_yaml_file(path, loader=ExtendedSafeLoader): with open(path) as fh: return load(fh, loader)
11254
Test/png/11254.png
# Write a function to find the last occurrence of a character in a string. def last_occurence_char(string, char): flag = -1 for i in range(len(string)): if string[i] == char: flag = i if flag == -1: return None else: return flag + 1
10432
Test/png/10432.png
def unique(list): unique = [] [unique.append(x) for x in list if x not in unique] return unique
11232
Test/png/11232.png
# Write a function to find the sum of maximum increasing subsequence of the given array. def max_sum_increasing_subsequence(arr, n): max = 0 msis = [0 for x in range(n)] for i in range(n): msis[i] = arr[i] for i in range(1, n): for j in range(i): if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]: msis[i] = msis[j] + arr[i] for i in range(n): if max < msis[i]: max = msis[i] return max
10924
Test/png/10924.png
# Write a function to check if a nested list is a subset of another nested list. def check_subset_list(list1, list2): l1, l2 = list1[0], list2[0] exist = True for i in list2: if i not in list1: exist = False return exist
10933
Test/png/10933.png
# Write a python function to find the minimum element in a sorted and rotated array. def find_Min(arr, low, high): while low < high: mid = low + (high - low) // 2 if arr[mid] == arr[high]: high -= 1 elif arr[mid] > arr[high]: low = mid + 1 else: high = mid return arr[high]
10824
Test/png/10824.png
# Write a function to convert a given tuple of positive integers into an integer. def tuple_to_int(nums): result = int("".join(map(str, nums))) return result
11157
Test/png/11157.png
# Write a python function to check whether the triangle is valid or not if 3 points are given. def check_Triangle(x1, y1, x2, y2, x3, y3): a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) if a == 0: return "No" else: return "Yes"
11066
Test/png/11066.png
# Write a function to find modulo division of two lists using map and lambda function. def moddiv_list(nums1, nums2): result = map(lambda x, y: x % y, nums1, nums2) return list(result)
11250
Test/png/11250.png
# Write a function to replace all occurrences of spaces, commas, or dots with a colon in the given string by using regex. import re def fill_spaces(text): return re.sub("[ ,.]", ":", text)
10895
Test/png/10895.png
# Write a function to find the longest common subsequence for the given two sequences. def longest_common_subsequence(X, Y, m, n): if m == 0 or n == 0: return 0 elif X[m - 1] == Y[n - 1]: return 1 + longest_common_subsequence(X, Y, m - 1, n - 1) else: return max( longest_common_subsequence(X, Y, m, n - 1), longest_common_subsequence(X, Y, m - 1, n), )
10840
Test/png/10840.png
# Write a function to convert tuple to a string. def tup_string(tup1): str = "".join(tup1) return str
10206
Test/png/10206.png
def DeleteLog() -> None: if os.path.exists(Logger.FileName): os.remove(Logger.FileName)
11291
Test/png/11291.png
# Write a function for nth catalan number. def catalan_number(num): if num <= 1: return 1 res_num = 0 for i in range(num): res_num += catalan_number(i) * catalan_number(num - i - 1) return res_num
10631
Test/png/10631.png
def positions(self): return [self.ode_obj.getPosition(i) for i in range(self.LDOF)]
11132
Test/png/11132.png
# Write a function to extract only the rear index element of each string in the given tuple. def extract_rear(test_tuple): res = list(sub[len(sub) - 1] for sub in test_tuple) return res
10114
Test/png/10114.png
def get_system_cpu_times(): user, nice, system, idle = _psutil_osx.get_system_cpu_times() return _cputimes_ntuple(user, nice, system, idle)
11210
Test/png/11210.png
# Write a python function to find remainder of two numbers. def find(n, m): r = n % m return r
10393
Test/png/10393.png
def remove_intent(self, name): self.intents.remove(name) self.padaos.remove_intent(name) self.must_train = True
10728
Test/png/10728.png
# Write a function to check if the given number is woodball or not. def is_woodall(x): if x % 2 == 0: return False if x == 1: return True x = x + 1 p = 0 while x % 2 == 0: x = x / 2 p = p + 1 if p == x: return True return False
10916
Test/png/10916.png
# Write a function to check the given decimal with a precision of 2 by using regex. import re def is_decimal(num): num_fetch = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""") result = num_fetch.search(num) return bool(result)
10317
Test/png/10317.png
def fillScreen(self, color=None): md.fill_rect(self.set, 0, 0, self.width, self.height, color)
10330
Test/png/10330.png
def serpentine_y(x, y, matrix): if x % 2: return x, matrix.rows - 1 - y return x, y
10421
Test/png/10421.png
def goal(self, x, y, z, d=50.0): return (x-self.x)/d, (y-self.y)/d, (z-self.z)/d
10658
Test/png/10658.png
def log_error(error, result): p = {'error': error, 'result': result} _log(TYPE_CODES.ERROR, p)
10608
Test/png/10608.png
def setsweeps(self): for sweep in range(self.sweeps): self.setsweep(sweep) yield self.sweep
10198
Test/png/10198.png
def pformat(o, indent=1, width=80, depth=None): return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(o)
10173
Test/png/10173.png
def height(self): if len(self.coords) <= 1: return 0 return np.max(self.yy) - np.min(self.yy)
10982
Test/png/10982.png
# Write a python function to find sum of even index binomial coefficients. import math def even_binomial_Coeff_Sum(n): return 1 << (n - 1)
11216
Test/png/11216.png
# Write a function to check if the common elements between two given lists are in the same order or not. def same_order(l1, l2): common_elements = set(l1) & set(l2) l1 = [e for e in l1 if e in common_elements] l2 = [e for e in l2 if e in common_elements] return l1 == l2
10238
Test/png/10238.png
def SWAP(self, *operands): a = operands[0] b = operands[-1] return (b,) + operands[1:-1] + (a,)
10224
Test/png/10224.png
def to_arr(this): return [this.get(str(e)) for e in xrange(len(this))]
10853
Test/png/10853.png
# Write a python function to find the maximum difference between any two elements in a given array. def max_Abs_Diff(arr, n): minEle = arr[0] maxEle = arr[0] for i in range(1, n): minEle = min(minEle, arr[i]) maxEle = max(maxEle, arr[i]) return maxEle - minEle
11113
Test/png/11113.png
# Write a function to check whether an element exists within a tuple. def check_tuplex(tuplex, tuple1): if tuple1 in tuplex: return True else: return False
10896
Test/png/10896.png
# Write a python function to check whether the given number can be represented by product of two squares or not. def prod_Square(n): for i in range(2, (n) + 1): if i * i < (n + 1): for j in range(2, n + 1): if (i * i * j * j) == n: return True return False
10720
Test/png/10720.png
# Write a function to sort a given matrix in ascending order according to the sum of its rows. def sort_matrix(M): result = sorted(M, key=sum) return result
10470
Test/png/10470.png
def file(self, filename): with open(filename) as f: self.lexer.input(f.read()) return self
10468
Test/png/10468.png
def scaling(self, x, y): self.drawer.append(pgmagick.DrawableScaling(float(x), float(y)))
11195
Test/png/11195.png
# Write a function to sort a list of tuples in increasing order by the last element in each tuple. def sort_tuple(tup): lst = len(tup) for i in range(0, lst): for j in range(0, lst - i - 1): if tup[j][-1] > tup[j + 1][-1]: temp = tup[j] tup[j] = tup[j + 1] tup[j + 1] = temp return tup
10256
Test/png/10256.png
def render_ranks(graph, ranks, dot_file="graph.dot"): if dot_file: write_dot(graph, ranks, path=dot_file)
10320
Test/png/10320.png
def color_scale(color, level): return tuple([int(i * level) >> 8 for i in list(color)])