common_id
stringlengths 5
5
| image
stringlengths 18
18
| code
stringlengths 55
1.44k
|
---|---|---|
10348 | Test/png/10348.png | def get_job_and_task_param(job_params, task_params, field):
return job_params.get(field, set()) | task_params.get(field, set())
|
10259 | Test/png/10259.png | def json_iter(path):
with open(path, 'r') as f:
for line in f.readlines():
yield json.loads(line)
|
10392 | Test/png/10392.png | def add_icon(icon_data, dest):
with open(os.path.join(dest, "icon.png"), "wb") as f:
f.write(icon_data)
|
10150 | Test/png/10150.png | def short_stack():
stack = inspect.stack()[:0:-1]
return "\n".join(["%30s : %s @%d" % (t[3], t[1], t[2]) for t in stack])
|
11197 | Test/png/11197.png | # Write a python function to find the frequency of the largest value in a given array.
def frequency_Of_Largest(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
|
10292 | Test/png/10292.png | def set_cfg_value(config, section, option, value):
if isinstance(value, list):
value = '\n'.join(value)
config[section][option] = value
|
10127 | Test/png/10127.png | def render_template(content, context):
rendered = Template(content).render(Context(context))
return rendered
|
10119 | Test/png/10119.png | def GOE(N):
m = ra.standard_normal((N, N))
m += m.T
return m/2
|
10919 | Test/png/10919.png | # Write a python function to count numbers whose oth and nth bits are set.
def count_Num(n):
if n == 1:
return 1
count = pow(2, n - 2)
return count
|
10810 | Test/png/10810.png | # Write a function to convert snake case string to camel case string.
def snake_to_camel(word):
import re
return "".join(x.capitalize() or "_" for x in word.split("_"))
|
10964 | Test/png/10964.png | # Write a python function to count the number of prime numbers less than a given non-negative number.
def count_Primes_nums(n):
ctr = 0
for num in range(n):
if num <= 1:
continue
for i in range(2, num):
if (num % i) == 0:
break
else:
ctr += 1
return ctr
|
10932 | Test/png/10932.png | # Write a python function to count set bits of a given number.
def count_Set_Bits(n):
count = 0
while n:
count += n & 1
n >>= 1
return count
|
11118 | Test/png/11118.png | # Write a function to find the minimum value in a given heterogeneous list.
def min_val(listval):
min_val = min(i for i in listval if isinstance(i, int))
return min_val
|
10975 | Test/png/10975.png | # Write a python function to find the sum of squares of first n odd natural numbers.
def square_Sum(n):
return int(n * (4 * n * n - 1) / 3)
|
10835 | Test/png/10835.png | # Write a function to multiply two integers without using the * operator in python.
def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1)
|
10805 | Test/png/10805.png | # Write a function to find frequency count of list of lists.
def frequency_lists(list1):
list1 = [item for sublist in list1 for item in sublist]
dic_data = {}
for num in list1:
if num in dic_data.keys():
dic_data[num] += 1
else:
key = num
value = 1
dic_data[key] = value
return dic_data
|
10732 | Test/png/10732.png | # Write a function to convert the given binary number to its decimal equivalent.
def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while binary != 0:
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary // 10
i += 1
return decimal
|
10699 | Test/png/10699.png | def create_patch(self, from_tag, to_tag):
return str(self._git.diff('{}..{}'.format(from_tag, to_tag), _tty_out=False))
|
11142 | Test/png/11142.png | # Write a function that matches a string that has an a followed by one or more b's.
import re
def text_match_one(text):
patterns = "ab+?"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
10278 | Test/png/10278.png | def _generate_index(self):
self._dict = {v.id: k for k, v in enumerate(self)}
|
10339 | Test/png/10339.png | def good(txt):
print("%s# %s%s%s" % (PR_GOOD_CC, get_time_stamp(), txt, PR_NC))
sys.stdout.flush()
|
11023 | Test/png/11023.png | # Write a python function to find the first maximum length of even word.
def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while i < n:
if str[i] == " ":
if currlen % 2 == 0:
if maxlen < currlen:
maxlen = currlen
st = i - currlen
currlen = 0
else:
currlen += 1
i += 1
if currlen % 2 == 0:
if maxlen < currlen:
maxlen = currlen
st = i - currlen
if st == -1:
return "-1"
return str[st : st + maxlen]
|
10515 | Test/png/10515.png | def setup(app):
if 'http' not in app.domains:
httpdomain.setup(app)
app.add_directive('autopyramid', RouteDirective)
|
10243 | Test/png/10243.png | def normal_noise(points):
return np.random.rand(1) * np.random.randn(points, 1) \
+ random.sample([2, -2], 1)
|
10980 | Test/png/10980.png | # Write a function to perfom the rear element extraction from list of tuples records.
def rear_extract(test_list):
res = [lis[-1] for lis in test_list]
return res
|
10620 | Test/png/10620.png | def reverse(self):
if not self.test_drive and self.bumps:
map(lambda b: b.reverse(), self.bumpers)
|
10871 | Test/png/10871.png | # Write a function to calculate the area of a regular polygon.
from math import tan, pi
def area_polygon(s, l):
area = s * (l**2) / (4 * tan(pi / s))
return area
|
11187 | Test/png/11187.png | # Write a python function to find the first digit of a given number.
def first_Digit(n):
while n >= 10:
n = n / 10
return int(n)
|
11260 | Test/png/11260.png | # Write a python function to check whether a given sequence is linear or not.
def Seq_Linear(seq_nums):
seq_nums = [seq_nums[x] - seq_nums[x - 1] for x in range(1, len(seq_nums))]
if len(set(seq_nums)) == 1:
return "Linear Sequence"
else:
return "Non Linear Sequence"
|
11229 | Test/png/11229.png | # Write a function to print check if the triangle is scalene or not.
def check_isosceles(x, y, z):
if x != y & y != z & z != x:
return True
else:
return False
|
11070 | Test/png/11070.png | # Write a python function to find the item with maximum occurrences in a given list.
def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
occu = nums.count(i)
if occu > max_val:
max_val = occu
result = i
return result
|
10129 | Test/png/10129.png | def splitBy(data, num):
return [data[i:i + num] for i in range(0, len(data), num)]
|
10346 | Test/png/10346.png | def fact(self, name):
facts = self.facts(name=name)
return next(fact for fact in facts)
|
10413 | Test/png/10413.png | def consume(self, kind):
next_token = self.stream.move()
assert next_token.kind == kind
|
10527 | Test/png/10527.png | def _mutagen_fields_to_single_value(metadata):
return dict((k, v[0]) for k, v in metadata.items() if v)
|
11224 | Test/png/11224.png | # Write a function to sort a list of elements using radix sort.
def radix_sort(nums):
RADIX = 10
placement = 1
max_digit = max(nums)
while placement < max_digit:
buckets = [list() for _ in range(RADIX)]
for i in nums:
tmp = int((i / placement) % RADIX)
buckets[tmp].append(i)
a = 0
for b in range(RADIX):
buck = buckets[b]
for i in buck:
nums[a] = i
a += 1
placement *= RADIX
return nums
|
10441 | Test/png/10441.png | def sha1(self):
with open(self.path, 'rb') as f:
return hashlib.sha1(f.read()).hexdigest()
|
10813 | Test/png/10813.png | # Write a python function to count true booleans in the given list.
def count(lst):
return sum(lst)
|
10363 | Test/png/10363.png | def delete_frames(self):
for frame in glob.glob(self.frameglob):
os.unlink(frame)
|
10334 | Test/png/10334.png | def unlock_wallet(self, *args, **kwargs):
self.blockchain.wallet.unlock(*args, **kwargs)
return self
|
11207 | Test/png/11207.png | # Write a function to find the diameter of a circle.
def diameter_circle(r):
diameter = 2 * r
return diameter
|
10294 | Test/png/10294.png | def data_two_freqs(N=200):
nn = arange(N)
xx = cos(0.257*pi*nn) + sin(0.2*pi*nn) + 0.01*randn(nn.size)
return xx
|
10307 | Test/png/10307.png | def add_next(self, requester: int, track: dict):
self.queue.insert(0, AudioTrack().build(track, requester))
|
10176 | Test/png/10176.png | def state_size(self):
return (LSTMStateTuple(self._num_units, self._num_units) if self._state_is_tuple else 2 * self._num_units)
|
10126 | Test/png/10126.png | def add(self, func, priority=0):
self.chain.append((priority, func))
self.chain.sort(key=lambda x: x[0])
|
10192 | Test/png/10192.png | def quote(c):
i = ord(c)
return ESCAPE + HEX[i//16] + HEX[i % 16]
|
10401 | Test/png/10401.png | def plot_axis(self, rs, theta):
xs, ys = get_cartesian(rs, theta)
self.ax.plot(xs, ys, 'black', alpha=0.3)
|
11054 | Test/png/11054.png | # Write a function to find entringer number e(n, k).
def zigzag(n, k):
if n == 0 and k == 0:
return 1
if k == 0:
return 0
return zigzag(n, k - 1) + zigzag(n - 1, n - k)
|
10207 | Test/png/10207.png | def write_json_response(self, response):
self.write(tornado.escape.json_encode(response))
self.set_header("Content-Type", "application/json")
|
10605 | Test/png/10605.png | def set_ip(self, ip):
self.set(ip=ip, netmask=self._nm)
|
11022 | Test/png/11022.png | # Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n.
def max_sum_rectangular_grid(grid, n):
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n):
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl)
|
11105 | Test/png/11105.png | # Write a function to find the median of three specific numbers.
def median_numbers(a, b, c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
return median
|
10640 | Test/png/10640.png | def register(self, model):
self.models[model._meta.table_name] = model
model._meta.database = self.database
return model
|
10501 | Test/png/10501.png | def build(ctx, project, build): # pylint:disable=redefined-outer-name
ctx.obj = ctx.obj or {}
ctx.obj['project'] = project
ctx.obj['build'] = build
|
10472 | Test/png/10472.png | def set_login(self, callsign, passwd="-1", skip_login=False):
self.__dict__.update(locals())
|
11288 | Test/png/11288.png | # Write a function to extract the even elements in the nested mixed tuple.
def even_ele(test_tuple, even_fnc):
res = tuple()
for ele in test_tuple:
if isinstance(ele, tuple):
res += (even_ele(ele, even_fnc),)
elif even_fnc(ele):
res += (ele,)
return res
def extract_even(test_tuple):
res = even_ele(test_tuple, lambda x: x % 2 == 0)
return res
|
11057 | Test/png/11057.png | # Write a python function to check whether the given string is a binary string or not.
def check(string):
p = set(string)
s = {"0", "1"}
if s == p or p == {"0"} or p == {"1"}:
return "Yes"
else:
return "No"
|
10467 | Test/png/10467.png | def create_all(engine, checkfirst=True):
Base.metadata.create_all(bind=engine, checkfirst=checkfirst)
|
11170 | Test/png/11170.png | # Write a function to find all possible combinations of the elements of a given list.
def combinations_list(list1):
if len(list1) == 0:
return [[]]
result = []
for el in combinations_list(list1[1:]):
result += [el, el + [list1[0]]]
return result
|
10196 | Test/png/10196.png | def free_temp(self, v):
self.used_temps.remove(v)
self.free_temps.add(v)
|
10650 | Test/png/10650.png | def _parse_allele_data(self):
return [Allele(sequence=x) for x in
[self.ref_allele] + self.alt_alleles]
|
10719 | Test/png/10719.png | # Write a python function to remove first and last occurrence of a given character from the string.
def remove_Occ(s, ch):
for i in range(len(s)):
if s[i] == ch:
s = s[0:i] + s[i + 1 :]
break
for i in range(len(s) - 1, -1, -1):
if s[i] == ch:
s = s[0:i] + s[i + 1 :]
break
return s
|
10861 | Test/png/10861.png | # Write a function to find the vertex of a parabola.
def parabola_vertex(a, b, c):
vertex = ((-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a)))
return vertex
|
10466 | Test/png/10466.png | def _df(self):
if not self._restricted:
return self.nsamples
return self.nsamples - self._X["tX"].shape[1]
|
10555 | Test/png/10555.png | def get_separator(self, i):
return i and self.separator[min(i - 1, len(self.separator) - 1)] or ''
|
10713 | Test/png/10713.png | # Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.
def count_ways(n):
A = [0] * (n + 1)
B = [0] * (n + 1)
A[0] = 1
A[1] = 0
B[0] = 0
B[1] = 1
for i in range(2, n + 1):
A[i] = A[i - 2] + 2 * B[i - 1]
B[i] = A[i - 1] + B[i - 2]
return A[n]
|
10791 | Test/png/10791.png | # Write a python function to find the character made by adding all the characters of the given string.
def get_Char(strr):
summ = 0
for i in range(len(strr)):
summ += ord(strr[i]) - ord("a") + 1
if summ % 26 == 0:
return ord("z")
else:
summ = summ % 26
return chr(ord("a") + summ - 1)
|
10594 | Test/png/10594.png | def mate(self, other):
"Return a new individual crossing self and other."
c = random.randrange(len(self.genes))
return self.__class__(self.genes[:c] + other.genes[c:])
|
10425 | Test/png/10425.png | def set_bot(self, bot):
self.bot = bot
self.sink.set_bot(bot)
|
10371 | Test/png/10371.png | def load_gltf(self):
with open(self.path) as fd:
self.meta = GLTFMeta(self.path, json.load(fd))
|
10923 | Test/png/10923.png | # Write a function to decode a run-length encoded given list.
def decode_list(alist):
def aux(g):
if isinstance(g, list):
return [(g[1], range(g[0]))]
else:
return [(g, [0])]
return [x for g in alist for x, R in aux(g) for i in R]
|
10269 | Test/png/10269.png | def cmd_kill(opts):
kill_signal = opts.signal if hasattr(opts, 'signal') else "SIGKILL"
__with_containers(opts, Blockade.kill, signal=kill_signal)
|
10588 | Test/png/10588.png | def index_collection(self, filenames):
"Index a whole collection of files."
for filename in filenames:
self.index_document(open(filename).read(), filename)
|
10646 | Test/png/10646.png | def get_play_status(self):
status = yield from self.handle_int(self.API.get('status'))
return self.PLAY_STATES.get(status)
|
10848 | Test/png/10848.png | # Write a function to extract elements that occur singly in the given tuple list.
def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return res
|
10475 | Test/png/10475.png | def full(shape, value, dtype='f8'):
shared = empty(shape, dtype)
shared[:] = value
return shared
|
10765 | Test/png/10765.png | # Write a python function to find the largest number that can be formed with the given digits.
def find_Max_Num(arr, n):
arr.sort(reverse=True)
num = arr[0]
for i in range(1, n):
num = num * 10 + arr[i]
return num
|
10507 | Test/png/10507.png | def _ordinal_metric(_v1, _v2, i1, i2, n_v):
if i1 > i2:
i1, i2 = i2, i1
return (np.sum(n_v[i1:(i2 + 1)]) - (n_v[i1] + n_v[i2]) / 2) ** 2
|
11098 | Test/png/11098.png | # Write a function to insert a given string at the beginning of all items in a list.
def add_string(list, string):
add_string = [string.format(i) for i in list]
return add_string
|
11055 | Test/png/11055.png | # Write a python function to count the number of squares in a rectangle.
def count_Squares(m, n):
if n < m:
temp = m
m = n
n = temp
return n * (n + 1) * (3 * m - n + 1) // 6
|
10573 | Test/png/10573.png | def save_model(self, request, obj, form, change):
obj.author = request.user
obj.save()
|
10516 | Test/png/10516.png | def append(self, key, value=MARKER, replace=True):
return self.add_item(key, value, replace=replace)
|
11264 | Test/png/11264.png | # Write a python function to count the pairs with xor as an odd number.
def find_Odd_Pair(A, N):
oddPair = 0
for i in range(0, N):
for j in range(i + 1, N):
if (A[i] ^ A[j]) % 2 != 0:
oddPair += 1
return oddPair
|
11208 | Test/png/11208.png | # Write a function to concatenate all elements of the given list into a string.
def concatenate_elements(list):
ans = " "
for i in list:
ans = ans + " " + i
return ans
|
10496 | Test/png/10496.png | def normalize(self, string):
return ''.join([self._normalize.get(x, x) for x in nfd(string)])
|
10215 | Test/png/10215.png | def add_key(self, key):
if key not in self.value:
self.value[key] = ReducedMetric(self.reducer)
|
10575 | Test/png/10575.png | def yaml_get_data(filename):
with open(filename, 'rb') as fd:
yaml_data = yaml.load(fd)
return yaml_data
return False
|
11014 | Test/png/11014.png | # Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i .
def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
dp[i][j] = dp[i - 1][i] + a[j]
else:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = dp[i - 1][j]
return dp[index][k]
|
10725 | Test/png/10725.png | # Write a function to find the perimeter of a square.
def square_perimeter(a):
perimeter = 4 * a
return perimeter
|
10815 | Test/png/10815.png | # Write a python function to count hexadecimal numbers for a given range.
def count_Hexadecimal(L, R):
count = 0
for i in range(L, R + 1):
if i >= 10 and i <= 15:
count += 1
elif i > 15:
k = i
while k != 0:
if k % 16 >= 10:
count += 1
k = k // 16
return count
|
10426 | Test/png/10426.png | def settings(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
|
10112 | Test/png/10112.png | def _append_svg(self, svg, before_prompt=False):
self._append_custom(self._insert_svg, svg, before_prompt)
|
10443 | Test/png/10443.png | def similar_to(partial_zipcode, zips=_zips):
return [z for z in zips if z["zip_code"].startswith(partial_zipcode)]
|
10724 | Test/png/10724.png | # Write a function to find sequences of lowercase letters joined with an underscore.
import re
def text_lowercase_underscore(text):
patterns = "^[a-z]+_[a-z]+$"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
10950 | Test/png/10950.png | # Write a function to count total characters in a string.
def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total
|
10190 | Test/png/10190.png | def _reportCommandLineUsageErrorAndExit(parser, message):
print(parser.get_usage())
print(message)
sys.exit(1)
|
11245 | Test/png/11245.png | # Write a python function to find the first repeated word in a given string.
def first_repeated_word(str1):
temp = set()
for word in str1.split():
if word in temp:
return word
else:
temp.add(word)
return "None"
|
10710 | Test/png/10710.png | # Write a function to find the similar elements from the given two tuple lists.
def similar_elements(test_tup1, test_tup2):
res = tuple(set(test_tup1) & set(test_tup2))
return res
|
10216 | Test/png/10216.png | def save_module(self, obj):
self.modules.add(obj)
self.save_reduce(subimport, (obj.__name__,), obj=obj)
|
10120 | Test/png/10120.png | def read_file(self, filename):
self.lines, self.arcs = self._read_file(filename)
|