common_id
stringlengths 5
5
| image
stringlengths 18
18
| code
stringlengths 55
1.44k
|
---|---|---|
10918 | Test/png/10918.png | # Write a function to check that the given string contains only a certain set of characters(in this case a-z, a-z and 0-9) by using regex.
import re
def is_allowed_specific_char(string):
get_char = re.compile(r"[^a-zA-Z0-9.]")
string = get_char.search(string)
return not bool(string)
|
11061 | Test/png/11061.png | # Write a function to remove a specified column from a given nested list.
def remove_column(list1, n):
for i in list1:
del i[n]
return list1
|
10154 | Test/png/10154.png | def create_hb_stream(self, kernel_id):
self._check_kernel_id(kernel_id)
return super(MappingKernelManager, self).create_hb_stream(kernel_id)
|
10694 | Test/png/10694.png | def dmap(fn, record):
values = (fn(v) for k, v in record.items())
return dict(itertools.izip(record, values))
|
10469 | Test/png/10469.png | def t_istringapostrophe_css_string(self, t):
r'[^\'@]+'
t.lexer.lineno += t.value.count('\n')
return t
|
10826 | Test/png/10826.png | # [link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list.
def string_to_list(string):
lst = list(string.split(" "))
return lst
|
10420 | Test/png/10420.png | def close(self):
self._con.commit()
self._cur.close()
self._con.close()
|
10908 | Test/png/10908.png | # Write a function to find all index positions of the maximum values in a given list.
def position_max(list1):
max_val = max(list1)
max_result = [i for i, j in enumerate(list1) if j == max_val]
return max_result
|
10407 | Test/png/10407.png | def sort_seeds(uhandle, usort):
cmd = ["sort", "-k", "2", uhandle, "-o", usort]
proc = sps.Popen(cmd, close_fds=True)
proc.communicate()
|
11010 | Test/png/11010.png | # Write a python function to find the most significant bit number which is also a set bit.
def set_Bit_Number(n):
if n == 0:
return 0
msb = 0
n = int(n / 2)
while n > 0:
n = int(n / 2)
msb += 1
return 1 << msb
|
10109 | Test/png/10109.png | def start(self, n):
self.n = n
return super(MPILauncher, self).start()
|
11258 | Test/png/11258.png | # Write a python function to find the maximum element in a sorted and rotated array.
def find_Max(arr, low, high):
if high < low:
return arr[0]
if high == low:
return arr[low]
mid = low + (high - low) // 2
if mid < high and arr[mid + 1] < arr[mid]:
return arr[mid]
if mid > low and arr[mid] < arr[mid - 1]:
return arr[mid - 1]
if arr[low] > arr[mid]:
return find_Max(arr, low, mid - 1)
else:
return find_Max(arr, mid + 1, high)
|
10372 | Test/png/10372.png | def get_bbox(self, primitive):
accessor = primitive.attributes.get('POSITION')
return accessor.min, accessor.max
|
10546 | Test/png/10546.png | def get(self, name):
for c in self.comps:
if c.category == name:
return c
return None
|
10329 | Test/png/10329.png | def serpentine_x(x, y, matrix):
if y % 2:
return matrix.columns - 1 - x, y
return x, y
|
10877 | Test/png/10877.png | # Write a function to calculate the nth pell number.
def get_pell(n):
if n <= 2:
return n
a = 1
b = 2
for i in range(3, n + 1):
c = 2 * b + a
a = b
b = c
return b
|
11139 | Test/png/11139.png | # Write a function that takes two lists and returns true if they have at least one common element.
def common_element(list1, list2):
result = False
for x in list1:
for y in list2:
if x == y:
result = True
return result
|
10681 | Test/png/10681.png | def unipath(*paths):
return os.path.normpath(expandpath(os.path.join(*paths)))
|
10567 | Test/png/10567.png | def return_letters_from_string(text):
out = ""
for letter in text:
if letter.isalpha():
out += letter
return out
|
10965 | Test/png/10965.png | # Write a function to swap two numbers.
def swap_numbers(a, b):
temp = a
a = b
b = temp
return (a, b)
|
10894 | Test/png/10894.png | # Write a function to search some literals strings in a string by using regex.
import re
def check_literals(text, patterns):
for pattern in patterns:
if re.search(pattern, text):
return "Matched!"
else:
return "Not Matched!"
|
10863 | Test/png/10863.png | # Write a python function to toggle all even bits of a given number.
def even_bit_toggle_number(n):
res = 0
count = 0
temp = n
while temp > 0:
if count % 2 == 1:
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res
|
11263 | Test/png/11263.png | # Write a python function to find the difference between sum of cubes of first n natural numbers and the sum of first n natural numbers.
def difference(n):
S = (n * (n + 1)) // 2
res = S * (S - 1)
return res
|
10911 | Test/png/10911.png | # Write a python function to find the hamming distance between given two integers.
def hamming_Distance(n1, n2):
x = n1 ^ n2
setBits = 0
while x > 0:
setBits += x & 1
x >>= 1
return setBits
|
10288 | Test/png/10288.png | def html(tag):
return (HTML_START.format(tag=tag), HTML_END.format(tag=tag))
|
10598 | Test/png/10598.png | def run(self, steps=1000):
"Run the Environment for given number of time steps."
for step in range(steps):
if self.is_done():
return
self.step()
|
10476 | Test/png/10476.png | def abort(self):
self.mutex.release()
self.turnstile.release()
self.mutex.release()
self.turnstile2.release()
|
11089 | Test/png/11089.png | # Write a function to sort a list of lists by a given index of the inner list.
from operator import itemgetter
def index_on_inner_list(list_data, index_no):
result = sorted(list_data, key=itemgetter(index_no))
return result
|
11038 | Test/png/11038.png | # Write a function to find all three, four, five characters long words in the given string by using regex.
import re
def find_char(text):
return re.findall(r"\b\w{3,5}\b", text)
|
10857 | Test/png/10857.png | # Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.
def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if (arr[i] == arr[j] + 1) or (arr[i] == arr[j] - 1):
dp[i] = max(dp[i], dp[j] + 1)
result = 1
for i in range(n):
if result < dp[i]:
result = dp[i]
return result
|
10633 | Test/png/10633.png | def angles(self):
return [self.ode_obj.getAngle(i) for i in range(self.ADOF)]
|
10364 | Test/png/10364.png | def getpath(self, section, option):
return os.path.expanduser(os.path.expandvars(self.get(section, option)))
|
11128 | Test/png/11128.png | # Write a python function to find the cube sum of first n even natural numbers.
def cube_Sum(n):
sum = 0
for i in range(1, n + 1):
sum += (2 * i) * (2 * i) * (2 * i)
return sum
|
10821 | Test/png/10821.png | # Write a function to check if a string represents an integer or not.
def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and all(
text[i] in "0123456789" for i in range(1, len(text))
):
return True
else:
return False
|
10342 | Test/png/10342.png | def import_parms(self, args):
for key, val in args.items():
self.set_parm(key, val)
|
11060 | Test/png/11060.png | # Write a python function to check whether all the characters in a given string are unique.
def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1, len(str)):
if str[i] == str[j]:
return False
return True
|
10774 | Test/png/10774.png | # Write a python function to count positive numbers in a list.
def pos_count(list):
pos_count = 0
for num in list:
if num >= 0:
pos_count += 1
return pos_count
|
10448 | Test/png/10448.png | def context(self):
if not self._context:
self._context = context.get_admin_context()
return self._context
|
10756 | Test/png/10756.png | # Write a python function to set all odd bits of a given number.
def odd_bit_set_number(n):
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 0:
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
11049 | Test/png/11049.png | # Write a function to convert the given set into ordered tuples.
def set_to_tuple(s):
t = tuple(sorted(s))
return t
|
10480 | Test/png/10480.png | def money(min=0, max=10):
value = random.choice(range(min * 100, max * 100))
return "%1.2f" % (float(value) / 100)
|
10529 | Test/png/10529.png | def fork(self, name):
fork = deepcopy(self)
self[name] = fork
return fork
|
10796 | Test/png/10796.png | # Write a function to get the frequency of the elements in a list.
import collections
def freq_count(list1):
freq_count = collections.Counter(list1)
return freq_count
|
10530 | Test/png/10530.png | def resolve_admin_type(admin):
if admin is current_user or isinstance(admin, UserMixin):
return 'User'
else:
return admin.__class__.__name__
|
10361 | Test/png/10361.png | def profile(self):
with rasterio.open(self.path, "r") as src:
return deepcopy(src.meta)
|
10823 | Test/png/10823.png | # Write a function to check whether all dictionaries in a list are empty or not.
def empty_dit(list1):
empty_dit = all(not d for d in list1)
return empty_dit
|
11236 | Test/png/11236.png | # Write a function to find the list of lists with minimum length.
def min_length(list1):
min_length = min(len(x) for x in list1)
min_list = min((x) for x in list1)
return (min_length, min_list)
|
10974 | Test/png/10974.png | # Write a function to find the lateral surface area of a cube.
def lateralsurface_cube(l):
LSA = 4 * (l * l)
return LSA
|
10746 | Test/png/10746.png | # Write a function to find the division of first even and odd number of a given list.
def div_even_odd(list1):
first_even = next((el for el in list1 if el % 2 == 0), -1)
first_odd = next((el for el in list1 if el % 2 != 0), -1)
return first_even / first_odd
|
10211 | Test/png/10211.png | def filter_spouts(table, header):
spouts_info = []
for row in table:
if row[0] == 'spout':
spouts_info.append(row)
return spouts_info, header
|
10232 | Test/png/10232.png | def _get_id(self):
id_ = self._last_id.value
self._last_id.value += 1
return id_
|
11009 | Test/png/11009.png | # Write a function to find the depth of a dictionary.
def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0
|
10499 | Test/png/10499.png | def qtm_version(self):
return await asyncio.wait_for(
self._protocol.send_command("qtmversion"), timeout=self._timeout
)
|
10960 | Test/png/10960.png | # Write a python function to convert complex numbers to polar coordinates.
import cmath
def convert(numbers):
num = cmath.polar(numbers)
return num
|
10591 | Test/png/10591.png | def exp_schedule(k=20, lam=0.005, limit=100):
"One possible schedule function for simulated annealing"
return lambda t: if_(t < limit, k * math.exp(-lam * t), 0)
|
10202 | Test/png/10202.png | def output_image_link(self, m):
return self.renderer.image_link(
m.group('url'), m.group('target'), m.group('alt'))
|
10162 | Test/png/10162.png | def resume(self):
for tracer in self.tracers:
tracer.start()
threading.settrace(self._installation_trace)
|
10492 | Test/png/10492.png | def replace_bases(self, old, new):
self.seq = self.seq.replace(old, new)
|
11091 | Test/png/11091.png | # Write a python function to toggle all odd bits of a given number.
def even_bit_toggle_number(n):
res = 0
count = 0
temp = n
while temp > 0:
if count % 2 == 0:
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res
|
10577 | Test/png/10577.png | def label_suspicious(self, reason):
self.suspicion_reasons.append(reason)
self.is_suspect = True
|
10155 | Test/png/10155.png | def spin_after(f, self, *args, **kwargs):
ret = f(self, *args, **kwargs)
self.spin()
return ret
|
10860 | Test/png/10860.png | # Write a function to sort the given array by using merge sort.
def merge(a, b):
c = []
while len(a) != 0 and len(b) != 0:
if a[0] < b[0]:
c.append(a[0])
a.remove(a[0])
else:
c.append(b[0])
b.remove(b[0])
if len(a) == 0:
c += b
else:
c += a
return c
def merge_sort(x):
if len(x) == 0 or len(x) == 1:
return x
else:
middle = len(x) // 2
a = merge_sort(x[:middle])
b = merge_sort(x[middle:])
return merge(a, b)
|
10730 | Test/png/10730.png | # Write a function to find the first duplicate element in a given array of integers.
def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate
|
11225 | Test/png/11225.png | # Write a python function to find the largest postive number from the given list.
def largest_pos(list1):
max = list1[0]
for x in list1:
if x > max:
max = x
return max
|
11004 | Test/png/11004.png | # Write a python function to count inversions in an array.
def get_Inv_Count(arr, n):
inv_count = 0
for i in range(n):
for j in range(i + 1, n):
if arr[i] > arr[j]:
inv_count += 1
return inv_count
|
10987 | Test/png/10987.png | # Write a function to find the nth decagonal number.
def is_num_decagonal(n):
return 4 * n * n - 3 * n
|
10380 | Test/png/10380.png | def add_texture_dir(self, directory):
dirs = list(self.TEXTURE_DIRS)
dirs.append(directory)
self.TEXTURE_DIRS = dirs
|
11031 | Test/png/11031.png | # Write a function to re-arrange the given array in alternating positive and negative items.
def right_rotate(arr, n, out_of_place, cur):
temp = arr[cur]
for i in range(cur, out_of_place, -1):
arr[i] = arr[i - 1]
arr[out_of_place] = temp
return arr
def re_arrange(arr, n):
out_of_place = -1
for index in range(n):
if out_of_place >= 0:
if (arr[index] >= 0 and arr[out_of_place] < 0) or (
arr[index] < 0 and arr[out_of_place] >= 0
):
arr = right_rotate(arr, n, out_of_place, index)
if index - out_of_place > 2:
out_of_place += 2
else:
out_of_place = -1
if out_of_place == -1:
if (arr[index] >= 0 and index % 2 == 0) or (
arr[index] < 0 and index % 2 == 1
):
out_of_place = index
return arr
|
10166 | Test/png/10166.png | def analysis(self, morf):
f, s, _, m, mf = self.analysis2(morf)
return f, s, m, mf
|
10479 | Test/png/10479.png | def job_title():
result = random.choice(get_dictionary('job_titles')).strip()
result = result.replace('#{N}', job_title_suffix())
return result
|
10310 | Test/png/10310.png | def seek(self, pos: int):
await self._lavalink.ws.send(op='seek', guildId=self.guild_id, position=pos)
|
11272 | Test/png/11272.png | # Write a python function to count unequal element pairs from the given array.
def count_Pairs(arr, n):
cnt = 0
for i in range(n):
for j in range(i + 1, n):
if arr[i] != arr[j]:
cnt += 1
return cnt
|
11213 | Test/png/11213.png | # Write a function to move all zeroes to the end of the given array.
def re_order(A):
k = 0
for i in A:
if i:
A[k] = i
k = k + 1
for i in range(k, len(A)):
A[i] = 0
return A
|
11048 | Test/png/11048.png | # Write a python function to find the sum of the three lowest positive numbers from a given list of numbers.
def sum_three_smallest_nums(lst):
return sum(sorted([x for x in lst if x > 0])[:3])
|
10462 | Test/png/10462.png | def _walk(self):
while self._todo:
args = self._todo.pop(0)
self._step(*args)
|
10792 | Test/png/10792.png | # Write a function to find the n-th number in newman conway sequence.
def sequence(n):
if n == 1 or n == 2:
return 1
else:
return sequence(sequence(n - 1)) + sequence(n - sequence(n - 1))
|
10739 | Test/png/10739.png | # Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
def func(nums, k):
import collections
d = collections.defaultdict(int)
for row in nums:
for i in row:
d[i] += 1
temp = []
import heapq
for key, v in d.items():
if len(temp) < k:
temp.append((v, key))
if len(temp) == k:
heapq.heapify(temp)
else:
if v > temp[0][0]:
heapq.heappop(temp)
heapq.heappush(temp, (v, key))
result = []
while temp:
v, key = heapq.heappop(temp)
result.append(key)
return result
|
10406 | Test/png/10406.png | def copy(self):
cp = copy.deepcopy(self)
cp.genotypes = allel.GenotypeArray(self.genotypes, copy=True)
return cp
|
10867 | Test/png/10867.png | # Write a function to print the season for the given month and day.
def month_season(month, days):
if month in ("January", "February", "March"):
season = "winter"
elif month in ("April", "May", "June"):
season = "spring"
elif month in ("July", "August", "September"):
season = "summer"
else:
season = "autumn"
if (month == "March") and (days > 19):
season = "spring"
elif (month == "June") and (days > 20):
season = "summer"
elif (month == "September") and (days > 21):
season = "autumn"
elif (month == "October") and (days > 21):
season = "autumn"
elif (month == "November") and (days > 21):
season = "autumn"
elif (month == "December") and (days > 20):
season = "winter"
return season
|
10255 | Test/png/10255.png | def status(self):
status = []
if self.provider:
status = self.provider.status(self.blocks.values())
return status
|
11050 | Test/png/11050.png | # Write a function to find the smallest range that includes at-least one element from each of the given arrays.
from heapq import heappop, heappush
class Node:
def __init__(self, value, list_num, index):
self.value = value
self.list_num = list_num
self.index = index
def __lt__(self, other):
return self.value < other.value
def find_minimum_range(list):
high = float("-inf")
p = (0, float("inf"))
pq = []
for i in range(len(list)):
heappush(pq, Node(list[i][0], i, 0))
high = max(high, list[i][0])
while True:
top = heappop(pq)
low = top.value
i = top.list_num
j = top.index
if high - low < p[1] - p[0]:
p = (low, high)
if j == len(list[i]) - 1:
return p
heappush(pq, Node(list[i][j + 1], i, j + 1))
high = max(high, list[i][j + 1])
|
10465 | Test/png/10465.png | def economic_qs_zeros(n):
Q0 = empty((n, 0))
Q1 = eye(n)
S0 = empty(0)
return ((Q0, Q1), S0)
|
10439 | Test/png/10439.png | def _in_git_repo():
ret = temple.utils.shell(
'git rev-parse', stderr=subprocess.DEVNULL, check=False)
return ret.returncode == 0
|
11265 | Test/png/11265.png | # Write a function to toggle characters case in a string.
def toggle_string(string):
string1 = string.swapcase()
return string1
|
11020 | Test/png/11020.png | # Write a function to find the volume of a cone.
import math
def volume_cone(r, h):
volume = (1.0 / 3) * math.pi * r * r * h
return volume
|
10876 | Test/png/10876.png | # Write a python function to find the frequency of a number in a given array.
def frequency(a, x):
count = 0
for i in a:
if i == x:
count += 1
return count
|
10934 | Test/png/10934.png | # Write a python function to remove the characters which have odd index values of a given string.
def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result
|
10610 | Test/png/10610.png | def pickle_save(thing, fname):
pickle.dump(thing, open(fname, "wb"), pickle.HIGHEST_PROTOCOL)
return thing
|