common_id
stringlengths 5
5
| image
stringlengths 18
18
| code
stringlengths 55
1.44k
|
---|---|---|
10676 | Test/png/10676.png | def apply(f, obj, *args, **kwargs):
return vectorize(f)(obj, *args, **kwargs)
|
11163 | Test/png/11163.png | # Write a function to check whether the given month number contains 31 days or not.
def check_monthnumb_number(monthnum2):
if (
monthnum2 == 1
or monthnum2 == 3
or monthnum2 == 5
or monthnum2 == 7
or monthnum2 == 8
or monthnum2 == 10
or monthnum2 == 12
):
return True
else:
return False
|
10328 | Test/png/10328.png | def hsv2rgb_spectrum(hsv):
h, s, v = hsv
return hsv2rgb_raw(((h * 192) >> 8, s, v))
|
10662 | Test/png/10662.png | def tz(self):
if not self._tz:
self._tz = tzlocal.get_localzone().zone
return self._tz
|
10257 | Test/png/10257.png | def text_rank(path):
graph = build_graph(json_iter(path))
ranks = nx.pagerank(graph)
return graph, ranks
|
10271 | Test/png/10271.png | def cmd_logs(opts):
config = load_config(opts.config)
b = get_blockade(config, opts)
puts(b.logs(opts.container).decode(encoding='UTF-8'))
|
10754 | Test/png/10754.png | # Write a python function to determine whether all the numbers are different from each other are not.
def test_distinct(data):
if len(data) == len(set(data)):
return True
else:
return False
|
10399 | Test/png/10399.png | def close(self):
tasks = self._get_close_tasks()
if tasks:
await asyncio.wait(tasks)
self._session = None
|
10297 | Test/png/10297.png | def main(argv=None):
if argv is None:
argv = sys.argv[1:]
cli = CommandLineTool()
return cli.run(argv)
|
10180 | Test/png/10180.png | def getOutputNames(self):
outputs = self.getSpec().outputs
return [outputs.getByIndex(i)[0] for i in xrange(outputs.getCount())]
|
10641 | Test/png/10641.png | def python_value(self, value):
if self.field_type == 'TEXT' and isinstance(value, str):
return self.loads(value)
return value
|
11106 | Test/png/11106.png | # Write a function to compute the sum of digits of each number of a given list.
def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit())
|
10419 | Test/png/10419.png | def delete(self):
i = self.index()
if i != None:
del self.canvas.layers[i]
|
11220 | Test/png/11220.png | # Write a function to count the element frequency in the mixed nested tuple.
def flatten(test_tuple):
for tup in test_tuple:
if isinstance(tup, tuple):
yield from flatten(tup)
else:
yield tup
def count_element_freq(test_tuple):
res = {}
for ele in flatten(test_tuple):
if ele not in res:
res[ele] = 0
res[ele] += 1
return res
|
10846 | Test/png/10846.png | # Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
def is_Sum_Of_Powers_Of_Two(n):
if n % 2 == 1:
return False
else:
return True
|
10925 | Test/png/10925.png | # Write a python function to find the first repeated character in a given string.
def first_Repeated_Char(str):
h = {}
for ch in str:
if ch in h:
return ch
else:
h[ch] = 0
return "\0"
|
10952 | Test/png/10952.png | # Write a python function to find the next perfect square greater than a given number.
import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN
|
10526 | Test/png/10526.png | def popUpItem(self, *args):
self.Press()
time.sleep(.5)
return self._menuItem(self, *args)
|
10321 | Test/png/10321.png | def report(function, *args, **kwds):
try:
function(*args, **kwds)
except Exception:
traceback.print_exc()
|
11102 | Test/png/11102.png | # Write a function to check if given tuple is distinct or not.
def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return res
|
10578 | Test/png/10578.png | def move_dot(self):
return self.__class__(self.production, self.pos + 1, self.lookahead)
|
11114 | Test/png/11114.png | # Write a python function to find the parity of a given number.
def find_Parity(x):
y = x ^ (x >> 1)
y = y ^ (y >> 2)
y = y ^ (y >> 4)
y = y ^ (y >> 8)
y = y ^ (y >> 16)
if y & 1:
return "Odd Parity"
return "Even Parity"
|
11037 | Test/png/11037.png | # Write a python function to count negative numbers in a list.
def neg_count(list):
neg_count = 0
for num in list:
if num <= 0:
neg_count += 1
return neg_count
|
10303 | Test/png/10303.png | def _spawn_heartbeat(self):
self.spawn(self._heartbeat)
self.spawn(self._heartbeat_timeout)
|
10517 | Test/png/10517.png | def _kwargs(self):
return dict(color=self.color, velocity=self.velocity, colors=self.colors)
|
10254 | Test/png/10254.png | def can_sequence(obj):
if istype(obj, sequence_types):
t = type(obj)
return t([can(i) for i in obj])
else:
return obj
|
10917 | Test/png/10917.png | # Write a function to delete the smallest element from the given heap and then insert a new item.
import heapq as hq
def heap_replace(heap, a):
hq.heapify(heap)
hq.heapreplace(heap, a)
return heap
|
11217 | Test/png/11217.png | # Write a python function to find the average of odd numbers till a given odd number.
def average_Odd(n):
if n % 2 == 0:
return "Invalid Input"
return -1
sm = 0
count = 0
while n >= 1:
count = count + 1
sm = sm + n
n = n - 2
return sm // count
|
10842 | Test/png/10842.png | # Write a python function to check whether the last element of given array is even or odd after performing an operation p times.
def check_last(arr, n, p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
|
10669 | Test/png/10669.png | def gmb(a, b):
return np.exp(np.log(a).mean() - np.log(b).mean())
|
10755 | Test/png/10755.png | # Write a python function to find the last digit when factorial of a divides factorial of b.
def compute_Last_Digit(A, B):
variable = 1
if A == B:
return 1
elif (B - A) >= 5:
return 0
else:
for i in range(A + 1, B + 1):
variable = (variable * (i % 10)) % 10
return variable % 10
|
10984 | Test/png/10984.png | # Write a function to find the volume of a cylinder.
def volume_cylinder(r, h):
volume = 3.1415 * r * r * h
return volume
|
10797 | Test/png/10797.png | # Write a function to find the closest smaller number than n.
def closest_num(N):
return N - 1
|
10398 | Test/png/10398.png | def sendmail(self, msg_from, msg_to, msg):
SMTP_dummy.msg_from = msg_from
SMTP_dummy.msg_to = msg_to
SMTP_dummy.msg = msg
|
10891 | Test/png/10891.png | # Write a function to count all the distinct pairs having a difference of k in any array.
def count_pairs(arr, n, k):
count = 0
for i in range(0, n):
for j in range(i + 1, n):
if arr[i] - arr[j] == k or arr[j] - arr[i] == k:
count += 1
return count
|
10140 | Test/png/10140.png | def already_used(self, tok):
if tok in self.jwts:
return True
self.jwts[tok] = time.time()
return False
|
10706 | Test/png/10706.png | def get_time(filename):
ts = os.stat(filename).st_mtime
return datetime.datetime.utcfromtimestamp(ts)
|
10979 | Test/png/10979.png | # Write a python function to find the sum of fifth power of first n even natural numbers.
def even_Power_Sum(n):
sum = 0
for i in range(1, n + 1):
j = 2 * i
sum = sum + (j * j * j * j * j)
return sum
|
10282 | Test/png/10282.png | def _f_gene(sid, prefix="G_"):
sid = sid.replace(SBML_DOT, ".")
return _clip(sid, prefix)
|
10305 | Test/png/10305.png | def fetch(self, key: object, default=None):
return self._user_data.get(key, default)
|
10416 | Test/png/10416.png | def angle(x0, y0, x1, y1):
return degrees(atan2(y1-y0, x1-x0))
|
11269 | Test/png/11269.png | # Write a function to assign with each element, its pair elements from other similar pairs in the given tuple.
def assign_elements(test_list):
res = dict()
for key, val in test_list:
res.setdefault(val, [])
res.setdefault(key, []).append(val)
return res
|
11158 | Test/png/11158.png | # Write a function to extract specified size of strings from a give list of string values.
def extract_string(str, l):
result = [e for e in str if len(e) == l]
return result
|
10133 | Test/png/10133.png | def html_to_text(content):
text = None
h2t = html2text.HTML2Text()
h2t.ignore_links = False
text = h2t.handle(content)
return text
|
10928 | Test/png/10928.png | # Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.
import re
def replace_max_specialchar(text, n):
return re.sub("[ ,.]", ":", text, n)
|
10139 | Test/png/10139.png | def enterEvent(self, event):
super(CallTipWidget, self).enterEvent(event)
self._hide_timer.stop()
|
11222 | Test/png/11222.png | # Write a function to find the summation of tuple elements in the given tuple list.
def sum_elements(test_tup):
res = sum(list(test_tup))
return res
|
10362 | Test/png/10362.png | def prehook(self, **kwargs):
cmd = ['smpd', '-s']
logger.info("Starting smpd: "+" ".join(cmd))
rc = subprocess.call(cmd)
return rc
|
10491 | Test/png/10491.png | def subseq(self, start, end):
return Fasta(self.id, self.seq[start:end])
|
10262 | Test/png/10262.png | def get_domain(self, domain_name):
return Domain.get_object(api_token=self.token, domain_name=domain_name)
|
10866 | Test/png/10866.png | # Write a python function to find k number of operations required to make all elements equal.
def min_Ops(arr, n, k):
max1 = max(arr)
res = 0
for i in range(0, n):
if (max1 - arr[i]) % k != 0:
return -1
else:
res += (max1 - arr[i]) / k
return int(res)
|
10922 | Test/png/10922.png | # Write a function to convert radians to degrees.
import math
def degree_radian(radian):
degree = radian * (180 / math.pi)
return degree
|
10268 | Test/png/10268.png | def cmd_destroy(opts):
config = load_config(opts.config)
b = get_blockade(config, opts)
b.destroy()
|
10540 | Test/png/10540.png | def _i2p(self, ind, coord):
return '-'.join([self.param_prefix, str(ind), coord])
|
10845 | Test/png/10845.png | # Write a function to find the ration of zeroes in an array of integers.
from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1 / n, 2)
|
10897 | Test/png/10897.png | # Write a python function to find the first missing positive number.
def first_Missing_Positive(arr, n):
ptr = 0
for i in range(n):
if arr[i] == 1:
ptr = 1
break
if ptr == 0:
return 1
for i in range(n):
if arr[i] <= 0 or arr[i] > n:
arr[i] = 1
for i in range(n):
arr[(arr[i] - 1) % n] += n
for i in range(n):
if arr[i] <= n:
return i + 1
return n + 1
|
10373 | Test/png/10373.png | def interleaves(self, info):
return info.byte_offset == self.component_type.size * self.components
|
10818 | Test/png/10818.png | # Write a function to extract the ranges that are missing from the given list with the given start range and end range values.
def extract_missing(test_list, strt_val, stop_val):
res = []
for sub in test_list:
if sub[0] > strt_val:
res.append((strt_val, sub[0]))
strt_val = sub[1]
if strt_val < stop_val:
res.append((strt_val, stop_val))
return res
|
11206 | Test/png/11206.png | # Write a python function to find gcd of two positive integers.
def gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range(int(y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd
|
10992 | Test/png/10992.png | # Write a function to check whether all items of a list are equal to a given string.
def check_element(list, element):
check_element = all(v == element for v in list)
return check_element
|
11181 | Test/png/11181.png | # Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.
def tuple_intersection(test_list1, test_list2):
res = set([tuple(sorted(ele)) for ele in test_list1]) & set(
[tuple(sorted(ele)) for ele in test_list2]
)
return res
|
10666 | Test/png/10666.png | def nmse(a, b):
return np.square(a - b).mean() / (a.mean() * b.mean())
|
10986 | Test/png/10986.png | # Write a function to find the element count that occurs before the record in the given tuple.
def count_first_elements(test_tup):
for count, ele in enumerate(test_tup):
if isinstance(ele, tuple):
break
return count
|
10926 | Test/png/10926.png | # Write a python function to find the minimum operations required to make two numbers equal.
import math
def min_Operations(A, B):
if A > B:
swap(A, B)
B = B // math.gcd(A, B)
return B - 1
|
10899 | Test/png/10899.png | # Write a function to check whether the given month name contains 30 days or not.
def check_monthnumber(monthname3):
if (
monthname3 == "April"
or monthname3 == "June"
or monthname3 == "September"
or monthname3 == "November"
):
return True
else:
return False
|
11119 | Test/png/11119.png | # Write a function to convert the given snake case string to camel case string by using regex.
import re
def snake_to_camel(word):
return "".join(x.capitalize() or "_" for x in word.split("_"))
|
11069 | Test/png/11069.png | # Write a function to remove empty lists from a given list of lists.
def remove_empty(list1):
remove_empty = [x for x in list1 if x]
return remove_empty
|
10445 | Test/png/10445.png | def operation_list(uploader):
files = uploader.file_list()
for f in files:
log.info("{file:30s} {size}".format(file=f[0], size=f[1]))
|
10767 | Test/png/10767.png | # Write a function to find the nth octagonal number.
def is_octagonal(n):
return 3 * n * n - 2 * n
|
10939 | Test/png/10939.png | # Write a function to find the maximum sum in the given right triangle of numbers.
def max_sum(tri, n):
if n > 1:
tri[1][1] = tri[1][1] + tri[0][0]
tri[1][0] = tri[1][0] + tri[0][0]
for i in range(2, n):
tri[i][0] = tri[i][0] + tri[i - 1][0]
tri[i][i] = tri[i][i] + tri[i - 1][i - 1]
for j in range(1, i):
if tri[i][j] + tri[i - 1][j - 1] >= tri[i][j] + tri[i - 1][j]:
tri[i][j] = tri[i][j] + tri[i - 1][j - 1]
else:
tri[i][j] = tri[i][j] + tri[i - 1][j]
return max(tri[n - 1])
|
10574 | Test/png/10574.png | def json_get_data(filename):
with open(filename) as fp:
json_data = json.load(fp)
return json_data
return False
|
10178 | Test/png/10178.png | def word_to_id(self, word):
if word in self.vocab:
return self.vocab[word]
else:
return self.unk_id
|
11108 | Test/png/11108.png | # Write a function to extract the frequency of unique tuples in the given list order irrespective.
def extract_freq(test_list):
res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
return res
|
11025 | Test/png/11025.png | # Write a function to reflect the modified run-length encoding from a list.
from itertools import groupby
def modified_encode(alist):
def ctr_ele(el):
if len(el) > 1:
return [len(el), el[0]]
else:
return el[0]
return [ctr_ele(list(group)) for key, group in groupby(alist)]
|
11116 | Test/png/11116.png | # Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.
import heapq
def k_smallest_pairs(nums1, nums2, k):
queue = []
def push(i, j):
if i < len(nums1) and j < len(nums2):
heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
push(0, 0)
pairs = []
while queue and len(pairs) < k:
_, i, j = heapq.heappop(queue)
pairs.append([nums1[i], nums2[j]])
push(i, j + 1)
if j == 0:
push(i + 1, 0)
return pairs
|
10886 | Test/png/10886.png | # Write a function to search some literals strings in a string.
import re
def string_literals(patterns, text):
for pattern in patterns:
if re.search(pattern, text):
return "Matched!"
else:
return "Not Matched!"
|
11255 | Test/png/11255.png | # Write a python function to find the sum of hamming distances of all consecutive numbers from o to n.
def Total_Hamming_Distance(n):
i = 1
sum = 0
while n // i > 0:
sum = sum + n // i
i = i * 2
return sum
|
11219 | Test/png/11219.png | # Write a python function to find minimum sum of factors of a given number.
def find_Min_Sum(num):
sum = 0
i = 2
while i * i <= num:
while num % i == 0:
sum += i
num /= i
i += 1
sum += num
return sum
|
10247 | Test/png/10247.png | def t_heredoc(self, t):
r'<<\S+\r?\n'
t.lexer.is_tabbed = False
self._init_heredoc(t)
t.lexer.begin('heredoc')
|
10125 | Test/png/10125.png | def patch_if_missing(obj, name, method):
setattr(obj, name, getattr(obj, name, method))
|
10260 | Test/png/10260.png | def get_object(cls, api_token):
acct = cls(token=api_token)
acct.load()
return acct
|
11125 | Test/png/11125.png | # Write a function to find common first element in given list of tuple.
def group_tuples(Input):
out = {}
for elem in Input:
try:
out[elem[0]].extend(elem[1:])
except KeyError:
out[elem[0]] = list(elem)
return [tuple(values) for values in out.values()]
|
10333 | Test/png/10333.png | def getAccountFromPrivateKey(self, wif):
pub = self.publickey_from_wif(wif)
return self.getAccountFromPublicKey(pub)
|
10760 | Test/png/10760.png | # Write a function to caluclate area of a parallelogram.
def parallelogram_area(b, h):
area = b * h
return area
|
10785 | Test/png/10785.png | # Write a python function to find the difference between sum of even and odd digits.
def is_Diff(n):
return n % 11 == 0
|
10841 | Test/png/10841.png | # Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.
def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums: nums < 0, nums))
return sum(sum_negativenum)
|
10521 | Test/png/10521.png | def get_citation_years(graph: BELGraph) -> List[Tuple[int, int]]:
return create_timeline(count_citation_years(graph))
|
10447 | Test/png/10447.png | def has_tag(self, model):
for tag in model.tags:
if self.is_tag(tag):
return True
return False
|
10865 | Test/png/10865.png | # Write a function to reflect the run-length encoding from a list.
from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)]
|
11082 | Test/png/11082.png | # Write a function to print all permutations of a given string including duplicates.
def permute_string(str):
if len(str) == 0:
return [""]
prev_list = permute_string(str[1 : len(str)])
next_list = []
for i in range(0, len(prev_list)):
for j in range(0, len(str)):
new_str = prev_list[i][0:j] + str[0] + prev_list[i][j : len(str) - 1]
if new_str not in next_list:
next_list.append(new_str)
return next_list
|
10368 | Test/png/10368.png | def filter(self, x):
y = signal.sosfilt(self.sos, x)
return y
|
11095 | Test/png/11095.png | # Write a python function to check whether the hexadecimal number is even or odd.
def even_or_odd(N):
l = len(N)
if (
N[l - 1] == "0"
or N[l - 1] == "2"
or N[l - 1] == "4"
or N[l - 1] == "6"
or N[l - 1] == "8"
or N[l - 1] == "A"
or N[l - 1] == "C"
or N[l - 1] == "E"
):
return "Even"
else:
return "Odd"
|
10783 | Test/png/10783.png | # Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(test_list, K):
res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]
return str(res)
|
11193 | Test/png/11193.png | # Write a function to find the largest palindromic number in the given array.
def is_palindrome(n):
divisor = 1
while n / divisor >= 10:
divisor *= 10
while n != 0:
leading = n // divisor
trailing = n % 10
if leading != trailing:
return False
n = (n % divisor) // 10
divisor = divisor // 100
return True
def largest_palindrome(A, n):
A.sort()
for i in range(n - 1, -1, -1):
if is_palindrome(A[i]):
return A[i]
return -1
|
10537 | Test/png/10537.png | def query_by_admin(cls, admin):
return cls.query.filter_by(
admin_type=resolve_admin_type(admin), admin_id=admin.get_id())
|
10771 | Test/png/10771.png | # Write a function to find the maximum difference between available pairs in the given tuple list.
def max_difference(test_list):
temp = [abs(b - a) for a, b in test_list]
res = max(temp)
return res
|
10910 | Test/png/10910.png | # Write a function to remove even characters in a string.
def remove_even(str1):
str2 = ""
for i in range(1, len(str1) + 1):
if i % 2 != 0:
str2 = str2 + str1[i - 1]
return str2
|
10868 | Test/png/10868.png | # Write a function to find x and y that satisfies ax + by = n.
def solution(a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ", i, ", y = ", int((n - (i * a)) / b))
return 0
i = i + 1
return "No solution"
|
10944 | Test/png/10944.png | # Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.
def No_of_Triangle(N, K):
if N < K:
return -1
else:
Tri_up = 0
Tri_up = ((N - K + 1) * (N - K + 2)) // 2
Tri_down = 0
Tri_down = ((N - 2 * K + 1) * (N - 2 * K + 2)) // 2
return Tri_up + Tri_down
|
11078 | Test/png/11078.png | # Write a function to sort a tuple by its float element.
def float_sort(price):
float_sort = sorted(price, key=lambda x: float(x[1]), reverse=True)
return float_sort
|
End of preview. Expand
in Dataset Viewer.
- Downloads last month
- 36