common_id
stringlengths
5
5
image
stringlengths
18
18
code
stringlengths
55
1.44k
11141
Test/png/11141.png
# Write a function to check whether the entered number is greater than the elements of the given array. def check_greater(arr, number): arr.sort() if number > arr[-1]: return "Yes, the entered number is greater than those in the array" else: return "No, entered number is less than those in the array"
10525
Test/png/10525.png
def get_pmids(graph: BELGraph, output: TextIO): for pmid in get_pubmed_identifiers(graph): click.echo(pmid, file=output)
11160
Test/png/11160.png
# Write a function that gives loss amount if the given amount has loss else return none. def loss_amount(actual_cost, sale_amount): if sale_amount > actual_cost: amount = sale_amount - actual_cost return amount else: return None
10988
Test/png/10988.png
# Write a function to search an element in the given array by using sequential search. def sequential_search(dlist, item): pos = 0 found = False while pos < len(dlist) and not found: if dlist[pos] == item: found = True else: pos = pos + 1 return found, pos
10551
Test/png/10551.png
def delete_acl(self, name): if name not in self._acl: return False del self._acl[name] return True
11107
Test/png/11107.png
# Write a function to perform the mathematical bitwise xor operation across the given tuples. def bitwise_xor(test_tup1, test_tup2): res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return res
10949
Test/png/10949.png
# Write a function to generate a 3d array having each element as '*'. def array_3d(m, n, o): array_3d = [[["*" for col in range(m)] for col in range(n)] for row in range(o)] return array_3d
11183
Test/png/11183.png
# Write a function to sort counter by value. from collections import Counter def sort_counter(dict1): x = Counter(dict1) sort_counter = x.most_common() return sort_counter
10396
Test/png/10396.png
def has_add_permission(self, request): return request.user.is_authenticated and request.user.is_active and request.user.is_staff
10601
Test/png/10601.png
def static(**kwargs): def wrap(fn): fn.func_globals['static'] = fn fn.__dict__.update(kwargs) return fn return wrap
10370
Test/png/10370.png
def _calc_hash_da(self, rs): self.hash_d = hash_(rs.get_state())[:6] self.hash_a = self.hash_d
10152
Test/png/10152.png
def chop(seq, size): def chunk(i): return seq[i:i+size] return map(chunk, xrange(0, len(seq), size))
11111
Test/png/11111.png
# Write a function to check if a url is valid or not using regex. import re def is_valid_URL(str): regex = ( "((http|https)://)(www.)?" + "[a-zA-Z0-9@:%._\\+~#?&//=]" + "{2,256}\\.[a-z]" + "{2,6}\\b([-a-zA-Z0-9@:%" + "._\\+~#?&//=]*)" ) p = re.compile(regex) if str == None: return False if re.search(p, str): return True else: return False
11148
Test/png/11148.png
# Write a function to find all adverbs and their positions in a given sentence. import re def find_adverb_position(text): for m in re.finditer(r"\w+ly", text): return (m.start(), m.end(), m.group(0))
10189
Test/png/10189.png
def __advancePhase(self): self.__currentPhase = self.__phaseCycler.next() self.__currentPhase.enterPhase() return
10336
Test/png/10336.png
def read(self, path): with open(path, "rb") as fout: memmove(self.m_buf, fout.read(self.m_size), self.m_size)
10709
Test/png/10709.png
# Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][]. R = 3 C = 3 def min_cost(cost, m, n): tc = [[0 for x in range(C)] for x in range(R)] tc[0][0] = cost[0][0] for i in range(1, m + 1): tc[i][0] = tc[i - 1][0] + cost[i][0] for j in range(1, n + 1): tc[0][j] = tc[0][j - 1] + cost[0][j] for i in range(1, m + 1): for j in range(1, n + 1): tc[i][j] = min(tc[i - 1][j - 1], tc[i - 1][j], tc[i][j - 1]) + cost[i][j] return tc[m][n]
10440
Test/png/10440.png
def _error(msg, *args): print(msg % args, file=sys.stderr) sys.exit(1)
10991
Test/png/10991.png
# Write a python function to check whether the frequency of each digit is less than or equal to the digit itself. def validate(n): for i in range(10): temp = n count = 0 while temp: if temp % 10 == i: count += 1 if count > i: return False temp //= 10 return True
10744
Test/png/10744.png
# Write a python function to find the nth digit in the proper fraction of two given numbers. def find_Nth_Digit(p, q, N): while N > 0: N -= 1 p *= 10 res = p // q p %= q return res
11176
Test/png/11176.png
# Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array. def max_product(arr, n): mpis = [0] * (n) for i in range(n): mpis[i] = arr[i] for i in range(1, n): for j in range(i): if arr[i] > arr[j] and mpis[i] < (mpis[j] * arr[i]): mpis[i] = mpis[j] * arr[i] return max(mpis)
10337
Test/png/10337.png
def start(self): self.__thread = Thread(target=self.__run, args=(True, False)) self.__thread.setDaemon(True) self.__thread.start()
10461
Test/png/10461.png
def _place_row(self, row, position): self._rows_in_grid[row] = RowInGrid(row, position)
11034
Test/png/11034.png
# Write a function to get the word with most number of occurrences in the given strings list. from collections import defaultdict def most_occurrences(test_list): temp = defaultdict(int) for sub in test_list: for wrd in sub.split(): temp[wrd] += 1 res = max(temp, key=temp.get) return str(res)
10200
Test/png/10200.png
def isdir(s): try: st = os.stat(s) except os.error: return False return stat.S_ISDIR(st.st_mode)
10412
Test/png/10412.png
def _send(self, stanza): self.fix_out_stanza(stanza) element = stanza.as_xml() self._write_element(element)
10799
Test/png/10799.png
# Write a function to check if a substring is present in a given list of string values. def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
10687
Test/png/10687.png
def _str_replacement(self, target, replacement): self.data = self.data.replace(target, replacement)
11110
Test/png/11110.png
# Write a function to compute the value of ncr%p. def ncr_modp(n, r, p): C = [0 for i in range(r + 1)] C[0] = 1 for i in range(1, n + 1): for j in range(min(i, r), 0, -1): C[j] = (C[j] + C[j - 1]) % p return C[r]
10998
Test/png/10998.png
# Write a function to find the list of lists with maximum length. def max_length(list1): max_length = max(len(x) for x in list1) max_list = max((x) for x in list1) return (max_length, max_list)
10261
Test/png/10261.png
def get_droplet(self, droplet_id): return Droplet.get_object(api_token=self.token, droplet_id=droplet_id)
11146
Test/png/11146.png
# Write a function to count bidirectional tuple pairs. def count_bidirectional(test_list): res = 0 for idx in range(0, len(test_list)): for iidx in range(idx + 1, len(test_list)): if ( test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0] ): res += 1 return str(res)
11033
Test/png/11033.png
# Write a python function to find the minimum number of squares whose sum is equal to a given number. def get_Min_Squares(n): if n <= 3: return n res = n for x in range(1, n + 1): temp = x * x if temp > n: break else: res = min(res, 1 + get_Min_Squares(n - temp)) return res
10103
Test/png/10103.png
def select_up(self): r, c = self._index self._select_index(r-1, c)
10604
Test/png/10604.png
def convert_nm(nm, notation=IP_DOT, inotation=IP_UNKNOWN, check=True): return _convert(nm, notation, inotation, _check=check, _isnm=True)
11290
Test/png/11290.png
# Write a function to check if a dictionary is empty or not. def my_dict(dict1): if bool(dict1): return False else: return True
10160
Test/png/10160.png
def report(self, morfs, directory=None): self.report_files(self.annotate_file, morfs, directory)
10763
Test/png/10763.png
# Write a function to find t-nth term of geometric series. import math def tn_gp(a, n, r): tn = a * (math.pow(r, n - 1)) return tn
11042
Test/png/11042.png
# Write a python function to check whether the triangle is valid or not if sides are given. def check_Validity(a, b, c): if (a + b <= c) or (a + c <= b) or (b + c <= a): return False else: return True
10571
Test/png/10571.png
def connect(self): self._ftp.connect() self._ftp.login(user=self._username, passwd=self._passwd)
11223
Test/png/11223.png
# Write a function to check if there is a subset with sum divisible by m. def modular_sum(arr, n, m): if n > m: return True DP = [False for i in range(m)] for i in range(n): if DP[0]: return True temp = [False for i in range(m)] for j in range(m): if DP[j] == True: if DP[(j + arr[i]) % m] == False: temp[(j + arr[i]) % m] = True for j in range(m): if temp[j]: DP[j] = True DP[arr[i] % m] = True return DP[0]
10382
Test/png/10382.png
def runnable_effects(self) -> List[Type[Effect]]: return [cls for cls in self.effect_classes if cls.runnable]
10697
Test/png/10697.png
def get_state(self): return [os.path.join(dp, f) for dp, _, fn in os.walk(self.dir) for f in fn]
10345
Test/png/10345.png
def clean_notify(self): return self.cleaned_data.get(self.Fields.NOTIFY, self.NotificationTypes.DEFAULT)
10417
Test/png/10417.png
def distance(x0, y0, x1, y1): return sqrt(pow(x1-x0, 2) + pow(y1-y0, 2))
10878
Test/png/10878.png
# Write a function to find sum of the numbers in a list between the indices of a specified range. def sum_range_list(list1, m, n): sum_range = 0 for i in range(m, n + 1, 1): sum_range += list1[i] return sum_range
10766
Test/png/10766.png
# Write a python function to check whether the given two integers have opposite sign or not. def opposite_Signs(x, y): return (x ^ y) < 0
10498
Test/png/10498.png
def heappush_max(heap, item): heap.append(item) _siftdown_max(heap, 0, len(heap) - 1)
10163
Test/png/10163.png
def _canonical_dir(self, morf): return os.path.split(CodeUnit(morf, self.file_locator).filename)[0]
10219
Test/png/10219.png
def generate(): data_bytes = bytearray(random.getrandbits(8) for i in range(REQID.REQID_SIZE)) return REQID(data_bytes)
11073
Test/png/11073.png
# Write a python function to count the number of digits of a given number. def count_Digit(n): count = 0 while n != 0: n //= 10 count += 1 return count
10236
Test/png/10236.png
def SGT(self, a, b): # http://gavwood.com/paper.pdf s0, s1 = to_signed(a), to_signed(b) return Operators.ITEBV(256, s0 > s1, 1, 0)
10892
Test/png/10892.png
# Write a function to find all the values in a list that are greater than a specified number. def greater_specificnum(list, num): greater_specificnum = all(x >= num for x in list) return greater_specificnum
10707
Test/png/10707.png
def is_date_type(cls): if not isinstance(cls, type): return False return issubclass(cls, date) and not issubclass(cls, datetime)
10460
Test/png/10460.png
def write(self, string): bytes_ = string.encode(self._encoding) self._file.write(bytes_)
10148
Test/png/10148.png
def wave_saver(u, x, y, t): global u_hist global t_hist t_hist.append(t) u_hist.append(1.0*u)
11273
Test/png/11273.png
# Write a python function to split a string into characters. def split(word): return [char for char in word]
10244
Test/png/10244.png
def uniform_noise(points): return np.random.rand(1) * np.random.uniform(points, 1) \ + random.sample([2, -2], 1)
10750
Test/png/10750.png
# Write a python function to find the sum of repeated elements in a given array. def find_Sum(arr, n): return sum([x for x in arr if arr.count(x) > 1])
11153
Test/png/11153.png
# Write a function to perform index wise multiplication of tuple elements in the given two tuples. def index_multiplication(test_tup1, test_tup2): res = tuple( tuple(a * b for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2) ) return res
11166
Test/png/11166.png
# Write a function to find the area of a rectangle. def rectangle_area(l, b): area = l * b return area
10563
Test/png/10563.png
def flush(self, line): # TODO -- maybe use echo? sys.stdout.write(line) sys.stdout.flush()
10433
Test/png/10433.png
def eof(self): return (not self.is_alive()) and self._queue.empty() or self._fd.closed
11064
Test/png/11064.png
# Write a function to find the third angle of a triangle using two angles. def find_angle(a, b): c = 180 - (a + b) return c
10358
Test/png/10358.png
def _image_name_from_url(url): find = r'https?://|[^\w]' replace = '_' return re.sub(find, replace, url).strip('_')
10779
Test/png/10779.png
# Write a function to sort a list of elements using comb sort. def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i + gaps]: nums[i], nums[i + gaps] = nums[i + gaps], nums[i] swapped = True i += 1 return nums
10511
Test/png/10511.png
def get_description(): with open(path.join(here, 'README.rst'), 'r') as f: data = f.read() return data
10583
Test/png/10583.png
def add(self, o): "Add an observation o to the distribution." self.smooth_for(o) self.dictionary[o] += 1 self.n_obs += 1 self.sampler = None
11252
Test/png/11252.png
# Write a function to flatten the tuple list to a string. def flatten_tuple(test_list): res = " ".join([idx for tup in test_list for idx in tup]) return res
10263
Test/png/10263.png
def get_ssh_key(self, ssh_key_id): return SSHKey.get_object(api_token=self.token, ssh_key_id=ssh_key_id)
10995
Test/png/10995.png
# Write a python function to find the sum of squares of first n even natural numbers. def square_Sum(n): return int(2 * n * (n + 1) * (2 * n + 1) / 3)
10510
Test/png/10510.png
def _get_col_index(name): index = string.ascii_uppercase.index col = 0 for c in name.upper(): col = col * 26 + index(c) + 1 return col
10490
Test/png/10490.png
def union_fill_gap(self, i): return Interval(min(self.start, i.start), max(self.end, i.end))
10559
Test/png/10559.png
def dump_deque(self, obj, class_name="collections.deque"): return {"$" + class_name: [self._json_convert(item) for item in obj]}
11162
Test/png/11162.png
# Write a function that matches a word containing 'z'. import re def text_match_wordz(text): patterns = "\w*z.\w*" if re.search(patterns, text): return "Found a match!" else: return "Not matched!"
10972
Test/png/10972.png
# Write a function to calculate a dog's age in dog's years. def dog_age(h_age): if h_age < 0: exit() elif h_age <= 2: d_age = h_age * 10.5 else: d_age = 21 + (h_age - 2) * 4 return d_age
10711
Test/png/10711.png
# Write a python function to identify non-prime numbers. import math def is_not_prime(n): result = False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: result = True return result
10639
Test/png/10639.png
def cleanup(self, app): if hasattr(self.database.obj, 'close_all'): self.database.close_all()
10691
Test/png/10691.png
def run(exercise, command): Popen(['nohup', command, exercise.path()], stdout=DEVNULL, stderr=DEVNULL)
11006
Test/png/11006.png
# Write a function to find the nested list elements which are present in another list. def intersection_nested_lists(l1, l2): result = [[n for n in lst if n in l1] for lst in l2] return result
11027
Test/png/11027.png
# Write a function to find all five characters long word in the given string by using regex. import re def find_long_word(text): return re.findall(r"\b\w{5}\b", text)
10169
Test/png/10169.png
def save_policy(self, path): with open(path, 'wb') as f: pickle.dump(self.policy, f)
10874
Test/png/10874.png
# Write a python function to count the pairs with xor as an even number. def find_even_Pair(A, N): evenPair = 0 for i in range(0, N): for j in range(i + 1, N): if (A[i] ^ A[j]) % 2 == 0: evenPair += 1 return evenPair
11283
Test/png/11283.png
# Write a python function to find nth number in a sequence which is not a multiple of a given number. def count_no(A, N, L, R): count = 0 for i in range(L, R + 1): if i % A != 0: count += 1 if count == N: break return i
10299
Test/png/10299.png
def url(self): url = self.name.encode('utf-8') return url_quote(url) + '/' + self.url_ext
11145
Test/png/11145.png
# Write a function to remove odd characters in a string. def remove_odd(str1): str2 = "" for i in range(1, len(str1) + 1): if i % 2 == 0: str2 = str2 + str1[i - 1] return str2
11109
Test/png/11109.png
# Write a function to perform index wise addition of tuple elements in the given two nested tuples. def add_nested_tuples(test_tup1, test_tup2): res = tuple( tuple(a + b for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2) ) return res
10726
Test/png/10726.png
# Write a function to remove characters from the first string which are present in the second string. NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return "".join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = "" str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind += 1 return lst_to_string(str_list[0:res_ind])
11262
Test/png/11262.png
# Write a python function to find odd numbers from a mixed list. def Split(list): od_li = [] for i in list: if i % 2 != 0: od_li.append(i) return od_li
10915
Test/png/10915.png
# Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions. def find_longest_repeating_subseq(str): n = len(str) dp = [[0 for k in range(n + 1)] for l in range(n + 1)] for i in range(1, n + 1): for j in range(1, n + 1): if str[i - 1] == str[j - 1] and i != j: dp[i][j] = 1 + dp[i - 1][j - 1] else: dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]) return dp[n][n]
11005
Test/png/11005.png
# Write a function to flatten a given nested list structure. def flatten_list(list1): result_list = [] if not list1: return result_list stack = [list(list1)] while stack: c_num = stack.pop() next = c_num.pop() if c_num: stack.append(c_num) if isinstance(next, list): if next: stack.append(list(next)) else: result_list.append(next) result_list.reverse() return result_list
10596
Test/png/10596.png
def result(self, state, row): "Place the next queen at the given row." col = state.index(None) new = state[:] new[col] = row return new
10138
Test/png/10138.png
def unregister_checker(self, checker): if checker in self._checkers: self._checkers.remove(checker)
10673
Test/png/10673.png
def cache_resolver(resolver, path): env = resolver.cache.find(path) if env: return env raise ResolveError
10375
Test/png/10375.png
def root_path(): module_dir = os.path.dirname(globals()['__file__']) return os.path.dirname(os.path.dirname(module_dir))
11270
Test/png/11270.png
# Write a python function to find the maximum length of sublist. def Find_Max_Length(lst): maxLength = max(len(x) for x in lst) return maxLength
10674
Test/png/10674.png
def launch(prompt_prefix=None): if prompt_prefix: os.environ['PROMPT'] = prompt(prompt_prefix) subprocess.call(cmd(), env=os.environ.data)
10757
Test/png/10757.png
# Write a function to extract every first or specified element from a given two-dimensional list. def specified_element(nums, N): result = [i[N] for i in nums] return result
10225
Test/png/10225.png
def match(self, string, pos): return self.pat.match(string, int(pos))
10768
Test/png/10768.png
# Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array. def max_len_sub(arr, n): mls = [] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1: mls[i] = mls[j] + 1 for i in range(n): if max < mls[i]: max = mls[i] return max